which one is thread safe?

quote:

 

It's not so much that they're not performed, it's that because you called a reactor API from a thread, which you are never ever ever allowed to do , you have put your program into a state where everything is completely broken, forever . Every future API call may produce bizarre, broken results, or no results, or random, inexplicable crashes.

You know, the normal way multithreaded programs work ;-).

To repeat: every API in twisted, with the sole exception of callFromThread (and by extension things which call callFromThread , like blockingCallFromThread ), is not thread safe . Unfortunately, putting in warnings for every single API would be both a code maintenance nightmare, so several users have discovered this constraint in the same way that you have, by calling an API and noticing something weird.

If you have some code which runs in a thread that needs to call a reactor API, use callFromThread or blockingCallFromThread and it will dispatch the call to the reactor thread, where everything should work smoothly. However, for stuff like timed calls, there's really no need to use threads at all, and they would needlessly complicate your program.

 

by Glyph

 

link: http://stackoverflow.com/questions/3220991/difference-between-loopingcall-and-callinthread-in-pythons-twisted

你可能感兴趣的:(python,twisted)