Hi,
I have a CPU bound method that releases the GIL for the expensive part:
def cpu_bound(*args):
# release the GIL
# compute
# acquire the GIL and return a value
I am using gevent and want to call this method in a separate thread, and having the main thread be notified when the result is available (i.e., when "cpu_bound" is done). What's the simplest way to do this? I looked at gevent.ThreadPool, but I am not sure which method to use:
apply_cb, apply_async, spawn, ...
I am more familiar with twisted, and there I would do something like:
def cpu_bound_result(*args):
result = cpu_bound(*args)
reactor.callFromThread(got_result, result)
def main_thread():
reactor. callInThread(cpu_bound_result, *args)
def got_result(result):
# process result in main thread
Thanks!
Alok