Last active
August 29, 2015 14:01
-
-
Save willkelly/a2722dfb0aa435acacee to your computer and use it in GitHub Desktop.
Make threads that return values in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
class ThreadFunction(threading.Thread): | |
def __init__(self, group=None, target=None, name=None, | |
args=(), kwargs={}, Verbose=None): | |
self._return = None | |
super(ThreadFunction, self).__init__(group, self._wrap(target), | |
name, args, kwargs, Verbose) | |
def _wrap(self, f): | |
def g(*args, **kwargs): | |
self._return = f(*args, **kwargs) | |
return g | |
def join(self): | |
super(ThreadFunction, self).join() | |
return self._return |
Author
willkelly
commented
May 10, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment