What functions, other than sleep(), can be interrupted by Ctrl-C?

James Matthews nytrokiss at gmail.com
Fri Feb 27 04:20:20 EST 2009


You can hook the it on the main thread and just pass it. And let the threads
execute.

On Thu, Feb 26, 2009 at 10:47 PM, Gabriel Genellina
<gagsl-py2 at yahoo.com.ar>wrote:

> En Thu, 26 Feb 2009 16:17:42 -0200, Maxim Khitrov <mkhitrov at gmail.com>
> escribió:
>
>
>  I'm looking for a function in the standard library or pywin32 package
>> that will block until a certain condition is met or it is interrupted
>> by Ctrl-C. For example, time.sleep() would have been perfect for my
>> needs if thread.interrupt_main() could interrupt the call from another
>> thread in the same way that Ctrl-C does. Unfortunately, that is not
>> the case.
>>
>> Another thing I tried was creating a pipe with os.pipe() and issuing a
>> read call on it. The event to exit was a single byte written to the
>> other end of the pipe, but Ctrl-C could not interrupt the read call.
>> The threading.Event class does not work for me, because it uses short
>> sleep intervals for timed waits. I need the reaction to be as close to
>> instant as possible, something like this will not do:
>>
>> while not <some condition is met>:
>>   sleep(0.01)
>>
>> I actually replaced threading.Event with my own version that uses
>> native Windows events, and waits on those also cannot be interrupted
>> by Ctrl-C. I'm trying to achieve the same effect as that while loop
>> and I don't care what the condition to exit is, but the loop needs to
>> exit as soon as the condition is met without waiting for up to X
>> additional milliseconds. Any ideas?
>>
>
> You may try MsgWaitForMultipleObjects - send a message to the main thread
> from the other thread.
> An alertable wait (like SleepEx) plus QueueUserAPC should work, I presume,
> but I've never actually tried in Python.
>
> --
> Gabriel Genellina
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
http://www.astorandblack.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090227/b8f8842a/attachment-0001.html>


More information about the Python-list mailing list