Windows - select.select, timeout and KeyboardInterrupt

Paul Moore p.f.moore at gmail.com
Fri May 7 04:48:01 EDT 2010


On 6 May, 20:58, Thomas Heller <thel... at ctypes.org> wrote:
> If you look at the source code for time.sleep(), which CAN be interrupted
> by pressing Ctrl-C, you will find that it is carefully programmed to be
> interruptible (sp?).  Which is not the case for select.select(), obviously.

Thanks - given this, would it be worth me submitting a documentation
patch noting that select.select is not interruptible on Windows?

> I guess the best way might be to split your select.select() call into several
> ones, using a smaller timeout like 1 second for example.

Yes, that's probably good enough for my case.

> BTW: I have experimented with calling the win32 function SetConsoleCtrlHandler()
> before the call to select.select().  This allows to install a python callback
> function which is called when Ctrl+C is pressed.  However it seems this callback
> is not able to interrupt the select() call - but it can 'raise SystemExit()'
> which will terminate the script.  Here is the code:

That's useful - I doubt I'll need it for this case, but I'll keep it
in mind for the future.

Thanks for the help.
Paul.



More information about the Python-list mailing list