Skip to content

Instantly share code, notes, and snippets.

@barbuza
Created January 26, 2012 14:51
Show Gist options
  • Save barbuza/1683115 to your computer and use it in GitHub Desktop.
Save barbuza/1683115 to your computer and use it in GitHub Desktop.
class ParallelWorker(threading.Thread):
def __init__(self, cb, fn, args, kwargs):
self._cb = cb
self._fn = fn
self._args = args
self._kwargs = kwargs
super(ParallelWorker, self).__init__()
def run(self):
result = self._fn(*self._args, **self._kwargs)
cb = functools.partial(self._cb, result)
ioloop.IOLoop().instance().add_callback(cb)
def parallel(fn):
def wrapper(*args, **kwargs):
callback = kwargs.pop("callback")
worker = ParallelWorker(callback, fn, args, kwargs)
worker.start()
def decor(*args, **kwargs):
return gen.Task(wrapper, *args, **kwargs)
return decor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment