-
-
Notifications
You must be signed in to change notification settings - Fork 719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support asynchronous tasks #5151
Changes from all commits
caaeeff
67f1a82
47c4080
430d81a
5e10aa8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2910,7 +2910,14 @@ async def execute(self, key): | |
try: | ||
e = self.executors[executor] | ||
ts.start_time = time() | ||
if "ThreadPoolExecutor" in str(type(e)): | ||
if iscoroutinefunction(function): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The addition of this check revealed that since our |
||
result = await apply_function_async( | ||
function, | ||
args2, | ||
kwargs2, | ||
self.scheduler_delay, | ||
) | ||
elif "ThreadPoolExecutor" in str(type(e)): | ||
result = await self.loop.run_in_executor( | ||
e, | ||
apply_function, | ||
|
@@ -3885,6 +3892,42 @@ def apply_function_simple( | |
return msg | ||
|
||
|
||
async def apply_function_async( | ||
function, | ||
args, | ||
kwargs, | ||
time_delay, | ||
): | ||
"""Run a function, collect information | ||
|
||
Returns | ||
------- | ||
msg: dictionary with status, result/error, timings, etc.. | ||
""" | ||
ident = threading.get_ident() | ||
start = time() | ||
try: | ||
result = await function(*args, **kwargs) | ||
except Exception as e: | ||
msg = error_message(e) | ||
msg["op"] = "task-erred" | ||
msg["actual-exception"] = e | ||
else: | ||
msg = { | ||
"op": "task-finished", | ||
"status": "OK", | ||
"result": result, | ||
"nbytes": sizeof(result), | ||
"type": type(result) if result is not None else None, | ||
} | ||
finally: | ||
end = time() | ||
msg["start"] = start + time_delay | ||
msg["stop"] = end + time_delay | ||
msg["thread"] = ident | ||
return msg | ||
|
||
|
||
def apply_function_actor( | ||
function, args, kwargs, execution_state, key, active_threads, active_threads_lock | ||
): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is because
dict.get
became hashable starting with Python 3.8. This is whytest_unhashable_function
was only failing in our Python 3.7 CI builds