devork

E pur si muove

Raising exceptions in threads

Saturday, June 06, 2009

It's not simply raising an exception in a thread that I want. I want to raise an exception in a thread from another thread. It's like sending signals to threads, only signals in pyhon can only be delivered to the main thread (for portability). But Python has a other asynchronous signaling system: exceptions.

I'd like to be able to do something like:

for t in threading.enumerate():
    thread.raise(MyAppDoesntWantYouAnymoreError)

Is this possible? Are there other ways to do this sort of thing?

Alternatively I might be happy with a fix for issue1856, but I do think it might be nice to be able to signal threads in an asynchronous way in any case.

3 comments:

Unknown said...

That is exaclty what I was looking for! Just slightly odd that this is only exposed on the C API, but I guess it's fine using c-types.

New comments are not allowed.

Subscribe to: Post Comments (Atom)