How To Force Execution Of A Different Thread
I have one main thread that does some rather CPU intensive operation. The thread has to hold a lock for all its calculations. Then there are some other threads which occasionally r
Solution 1:
Merely releasing the GIL doesn't guarantee that other threads will have a chance to run.
In Unix, the call you really want is sched_yield()
. There's no interface to that function in the Python standard library; it would be straightforward to add one with a native module.
usleep(0)
and select()
are sometimes used for the same purpose, though it's not always the same depending on the system scheduler. Windows, you want Sleep(0). Use time.sleep(0) for both of those.
Solution 2:
Calling select.select()
with a timeout of 0 will release the GIL for a brief moment.
Post a Comment for "How To Force Execution Of A Different Thread"