[Twisted-Python] Exit all threads upon KeyboardInterrupt
Glyph Lefkowitz
glyph at twistedmatrix.com
Mon Jan 13 16:31:37 MST 2014
On Jan 12, 2014, at 4:42 PM, johnnadre <johnnadre at zoho.com> wrote:
>
> ---- On Sun, 12 Jan 2014 14:03:24 -0800 <exarkun at twistedmatrix.com> wrote ----
>
>> On 09:01 pm, johnnadre at zoho.com wrote:
>>>
>>> Hi,
>>>
>>> I want to exit my application immediately when CTRL+C is pressed,
>>> however reactor hangs when there are running threads.
>>> Some of these threads have blocking I/O, so I can't simply set a
>>> variable or wait for them to terminate. An example application would
>>> be:
>>
>> Python threads (being plain old operating systems; for example, POSIX
>> threads) aren't generally interruptable. You could try exiting the
>> entire process using `os._exit`.
Well, there's always pthread_kill, now exposed as os.pthread_kill on Python 3.3, but ... don't do that. Nothing good will come of it.
>> This is the case whether you're using Twisted or not.
>
> Thanks! That's exactly what I was looking for.
If you need to use os._exit, your application probably has a bug :-).
(Not to say you should never use it, but any time you use it you should be simultaneously looking into why you need to.)
-glyph
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4124 bytes
Desc: not available
URL: </pipermail/twisted-python/attachments/20140113/4afdcc1a/attachment-0002.bin>
More information about the Twisted-Python
mailing list