Skip to content

Instantly share code, notes, and snippets.

@saghul
Created November 9, 2012 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saghul/4048428 to your computer and use it in GitHub Desktop.
Save saghul/4048428 to your computer and use it in GitHub Desktop.
class _WorkItem(object):
def __init__(self, future, fn, args, kwargs):
self.future = future
self.fn = fn
self.args = args
self.kwargs = kwargs
def run(self):
if not self.future.set_running_or_notify_cancel():
return
try:
result = self.fn(*self.args, **self.kwargs)
except BaseException as e:
self.future.set_exception(e)
else:
self.future.set_result(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment