diff options
| author | Joshua Harlow <harlowja@yahoo-inc.com> | 2014-04-10 19:08:07 -0700 |
|---|---|---|
| committer | Joshua Harlow <harlowja@gmail.com> | 2014-04-10 23:45:45 -0700 |
| commit | 1930cbad7d4ef0d2f3c462c9a8ee346d75757a56 (patch) | |
| tree | 5530d2852778c4e82610da70ef359453aa12a48e /taskflow/utils/threading_utils.py | |
| parent | 2be76ee7d3e62558f04b1d6981c8cf6781ab3142 (diff) | |
| download | taskflow-1930cbad7d4ef0d2f3c462c9a8ee346d75757a56.tar.gz | |
Move the daemon thread helper function
This function seems better suited in the threading_utils module.
Change-Id: Iddd438b57973c7c6c26bd7b6239630656530bd1b
Diffstat (limited to 'taskflow/utils/threading_utils.py')
| -rw-r--r-- | taskflow/utils/threading_utils.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/taskflow/utils/threading_utils.py b/taskflow/utils/threading_utils.py index 0e2d1d0..c669619 100644 --- a/taskflow/utils/threading_utils.py +++ b/taskflow/utils/threading_utils.py @@ -15,6 +15,7 @@ # under the License. import multiprocessing +import threading import six @@ -34,3 +35,13 @@ def get_optimal_thread_count(): # just setup two threads since it's hard to know what else we # should do in this situation. return 2 + + +def daemon_thread(target, *args, **kwargs): + """Makes a daemon thread that calls the given target when started.""" + thread = threading.Thread(target=target, args=args, kwargs=kwargs) + # NOTE(skudriashev): When the main thread is terminated unexpectedly + # and thread is still alive - it will prevent main thread from exiting + # unless the daemon property is set to True. + thread.daemon = True + return thread |
