Add @threaded decorator (#7813)

* Add `@threaded` decorator

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Glenn Jocherandpre-commit-ci[bot] authored and GitHub committed 2022-05-14 16:12:08 +02:00
1 parent 9d8ed37df7
commit 4a295b1a89
5 files changed
+25 -17

No files matched your search

+11
View File
@@ -14,6 +14,7 @@ import random
import re
import shutil
import signal
import threading
import time
import urllib
from datetime import datetime
@@ -167,6 +168,16 @@ def try_except(func):
return handler
def threaded(func):
# Multi-threads a target function and returns thread. Usage: @threaded decorator
def wrapper(*args, **kwargs):
thread = threading.Thread(target=func, args=args, kwargs=kwargs, daemon=True)
thread.start()
return thread
return wrapper
def methods(instance):
# Get class/instance methods
return [f for f in dir(instance) if callable(getattr(instance, f)) and not f.startswith("__")]