|
7 | 7 | import sys
|
8 | 8 | import traceback
|
9 | 9 | import tempfile
|
10 |
| -import threading |
11 | 10 | from asgiref.sync import sync_to_async
|
12 | 11 | from datetime import timedelta
|
13 | 12 | from gettext import gettext as _
|
|
18 | 17 | from django_guid import get_guid
|
19 | 18 | from pulpcore.app.apps import MODULE_PLUGIN_VERSIONS
|
20 | 19 | from pulpcore.app.models import Task, TaskGroup
|
21 |
| -from pulpcore.app.util import current_task, get_domain, get_prn, deprecation_logger |
| 20 | +from pulpcore.app.util import ( |
| 21 | + current_task, |
| 22 | + get_domain, |
| 23 | + get_prn, |
| 24 | + deprecation_logger, |
| 25 | + force_deferred_execution, |
| 26 | +) |
22 | 27 | from pulpcore.constants import (
|
23 | 28 | TASK_FINAL_STATES,
|
24 | 29 | TASK_INCOMPLETE_STATES,
|
@@ -126,12 +131,6 @@ def _execute_task(task):
|
126 | 131 | send_task_notification(task)
|
127 | 132 |
|
128 | 133 |
|
129 |
| -def running_from_thread_pool() -> bool: |
130 |
| - thread_name = threading.current_thread().name |
131 |
| - # ThreadPoolExecutor names threads like: "ThreadPoolExecutor-0_0" |
132 |
| - return "ThreadPoolExecutor" in thread_name |
133 |
| - |
134 |
| - |
135 | 134 | def dispatch(
|
136 | 135 | func,
|
137 | 136 | args=None,
|
@@ -179,13 +178,10 @@ def dispatch(
|
179 | 178 | ValueError: When `resources` is an unsupported type.
|
180 | 179 | """
|
181 | 180 |
|
| 181 | + # Can't run short tasks immediately from certain contexts (e.g, if running from thread pool) |
| 182 | + immediate = immediate and not force_deferred_execution |
182 | 183 | assert deferred or immediate, "A task must be at least `deferred` or `immediate`."
|
183 | 184 |
|
184 |
| - # Can't run short tasks immediately if running from thread pool |
185 |
| - force_defer = True if running_from_thread_pool() else False |
186 |
| - short = immediate |
187 |
| - immediate = short and not force_defer |
188 |
| - |
189 | 185 | if callable(func):
|
190 | 186 | function_name = f"{func.__module__}.{func.__name__}"
|
191 | 187 | else:
|
|
0 commit comments