Skip to content
Snippets Groups Projects
Commit 3f992ea9 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

added optional `delay` argument to `call_in_separate_thread`

parent cb8637c4
No related branches found
No related tags found
No related merge requests found
# v2.14.47
* more time-related calls will accept time strings
* added optional `delay` argument to `call_in_separate_thread`
__version__ = '2.14.47a2'
__version__ = '2.14.47a3'
......@@ -14,7 +14,7 @@ from ..typing import ExceptionList
from ...exceptions import ResourceLocked, WouldWaitMore
def call_in_separate_thread(*t_args, **t_kwargs):
def call_in_separate_thread(*t_args, delay: float = 0, **t_kwargs):
"""
Decorator to mark given routine as callable in a separate thread.
......@@ -23,6 +23,8 @@ def call_in_separate_thread(*t_args, **t_kwargs):
The arguments given here will be passed to thread's constructor, so use like:
:param delay: seconds to wait before launching function
>>> @call_in_separate_thread(daemon=True)
>>> def handle_messages():
>>> while True:
......@@ -40,6 +42,8 @@ def call_in_separate_thread(*t_args, **t_kwargs):
def run(self):
if not self.future.set_running_or_notify_cancel():
return
if delay:
time.sleep(delay)
try:
res = fun(*args, **kwargs)
self.future.set_result(res)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment