Skip to content
Discussion options

You must be logged in to vote

Like the text says, that example shows how to "write and fetch" exceptions, it's probably not the best example for the chapter heading.

But I have to apologize, I just now looked closer at your example and I didn't consider before that Tokio's spawn_blocking must obviously run its closure in a thread pool, so the raising thread is not the thread you want an exception to be run in.

This can be done but is not encouraged. You'd need to use PyThreadState_SetAsyncExc like shown here but it is not wrapped in PyO3, so you need to work with the raw ffi binding.

A much better solution would be to use a flag, event, queue or other synchronization method to signal the other thread to stop.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@sbstp
Comment options

@birkenfeld
Comment options

Answer selected by sbstp
@sbstp
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants