asgiref 3.10.0__py3-none-any.whl → 3.11.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- asgiref/__init__.py +1 -1
- asgiref/sync.py +10 -2
- {asgiref-3.10.0.dist-info → asgiref-3.11.0.dist-info}/METADATA +1 -1
- {asgiref-3.10.0.dist-info → asgiref-3.11.0.dist-info}/RECORD +7 -7
- {asgiref-3.10.0.dist-info → asgiref-3.11.0.dist-info}/WHEEL +0 -0
- {asgiref-3.10.0.dist-info → asgiref-3.11.0.dist-info}/licenses/LICENSE +0 -0
- {asgiref-3.10.0.dist-info → asgiref-3.11.0.dist-info}/top_level.txt +0 -0
asgiref/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "3.
|
|
1
|
+
__version__ = "3.11.0"
|
asgiref/sync.py
CHANGED
|
@@ -424,6 +424,7 @@ class SyncToAsync(Generic[_P, _R]):
|
|
|
424
424
|
func: Callable[_P, _R],
|
|
425
425
|
thread_sensitive: bool = True,
|
|
426
426
|
executor: Optional["ThreadPoolExecutor"] = None,
|
|
427
|
+
context: Optional[contextvars.Context] = None,
|
|
427
428
|
) -> None:
|
|
428
429
|
if (
|
|
429
430
|
not callable(func)
|
|
@@ -432,6 +433,7 @@ class SyncToAsync(Generic[_P, _R]):
|
|
|
432
433
|
):
|
|
433
434
|
raise TypeError("sync_to_async can only be applied to sync functions.")
|
|
434
435
|
self.func = func
|
|
436
|
+
self.context = context
|
|
435
437
|
functools.update_wrapper(self, func)
|
|
436
438
|
self._thread_sensitive = thread_sensitive
|
|
437
439
|
markcoroutinefunction(self)
|
|
@@ -480,7 +482,7 @@ class SyncToAsync(Generic[_P, _R]):
|
|
|
480
482
|
# Use the passed in executor, or the loop's default if it is None
|
|
481
483
|
executor = self._executor
|
|
482
484
|
|
|
483
|
-
context = contextvars.copy_context()
|
|
485
|
+
context = contextvars.copy_context() if self.context is None else self.context
|
|
484
486
|
child = functools.partial(self.func, *args, **kwargs)
|
|
485
487
|
func = context.run
|
|
486
488
|
task_context: List[asyncio.Task[Any]] = []
|
|
@@ -518,7 +520,8 @@ class SyncToAsync(Generic[_P, _R]):
|
|
|
518
520
|
exec_coro.cancel()
|
|
519
521
|
ret = await exec_coro
|
|
520
522
|
finally:
|
|
521
|
-
|
|
523
|
+
if self.context is None:
|
|
524
|
+
_restore_context(context)
|
|
522
525
|
self.deadlock_context.set(False)
|
|
523
526
|
|
|
524
527
|
return ret
|
|
@@ -611,6 +614,7 @@ def sync_to_async(
|
|
|
611
614
|
*,
|
|
612
615
|
thread_sensitive: bool = True,
|
|
613
616
|
executor: Optional["ThreadPoolExecutor"] = None,
|
|
617
|
+
context: Optional[contextvars.Context] = None,
|
|
614
618
|
) -> Callable[[Callable[_P, _R]], Callable[_P, Coroutine[Any, Any, _R]]]:
|
|
615
619
|
...
|
|
616
620
|
|
|
@@ -621,6 +625,7 @@ def sync_to_async(
|
|
|
621
625
|
*,
|
|
622
626
|
thread_sensitive: bool = True,
|
|
623
627
|
executor: Optional["ThreadPoolExecutor"] = None,
|
|
628
|
+
context: Optional[contextvars.Context] = None,
|
|
624
629
|
) -> Callable[_P, Coroutine[Any, Any, _R]]:
|
|
625
630
|
...
|
|
626
631
|
|
|
@@ -630,6 +635,7 @@ def sync_to_async(
|
|
|
630
635
|
*,
|
|
631
636
|
thread_sensitive: bool = True,
|
|
632
637
|
executor: Optional["ThreadPoolExecutor"] = None,
|
|
638
|
+
context: Optional[contextvars.Context] = None,
|
|
633
639
|
) -> Union[
|
|
634
640
|
Callable[[Callable[_P, _R]], Callable[_P, Coroutine[Any, Any, _R]]],
|
|
635
641
|
Callable[_P, Coroutine[Any, Any, _R]],
|
|
@@ -639,9 +645,11 @@ def sync_to_async(
|
|
|
639
645
|
f,
|
|
640
646
|
thread_sensitive=thread_sensitive,
|
|
641
647
|
executor=executor,
|
|
648
|
+
context=context,
|
|
642
649
|
)
|
|
643
650
|
return SyncToAsync(
|
|
644
651
|
func,
|
|
645
652
|
thread_sensitive=thread_sensitive,
|
|
646
653
|
executor=executor,
|
|
654
|
+
context=context,
|
|
647
655
|
)
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
asgiref/__init__.py,sha256=
|
|
1
|
+
asgiref/__init__.py,sha256=cpptu6yAKjujkKCECVRXYkw3SmUpyBiTvJvB3Mmcu5s,23
|
|
2
2
|
asgiref/compatibility.py,sha256=DhY1SOpOvOw0Y1lSEjCqg-znRUQKecG3LTaV48MZi68,1606
|
|
3
3
|
asgiref/current_thread_executor.py,sha256=42CU1VODLTk-_PYise-cP1XgyAvI5Djc8f97owFzdrs,4157
|
|
4
4
|
asgiref/local.py,sha256=ZZeWWIXptVU4GbNApMMWQ-skuglvodcQA5WpzJDMxh4,4912
|
|
5
5
|
asgiref/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
6
|
asgiref/server.py,sha256=3A68169Nuh2sTY_2O5JzRd_opKObWvvrEFcrXssq3kA,6311
|
|
7
|
-
asgiref/sync.py,sha256=
|
|
7
|
+
asgiref/sync.py,sha256=kYfWtf4CI438zIw85kX9YQx0y64B1N6AM0PcRGf01M4,22927
|
|
8
8
|
asgiref/testing.py,sha256=U5wcs_-ZYTO5SIGfl80EqRAGv_T8BHrAhvAKRuuztT4,4421
|
|
9
9
|
asgiref/timeout.py,sha256=LtGL-xQpG8JHprdsEUCMErJ0kNWj4qwWZhEHJ3iKu4s,3627
|
|
10
10
|
asgiref/typing.py,sha256=Zi72AZlOyF1C7N14LLZnpAdfUH4ljoBqFdQo_bBKMq0,6290
|
|
11
11
|
asgiref/wsgi.py,sha256=J8OAgirfsYHZmxxqIGfFiZ43uq1qKKv2xGMkRISNIo4,6742
|
|
12
|
-
asgiref-3.
|
|
13
|
-
asgiref-3.
|
|
14
|
-
asgiref-3.
|
|
15
|
-
asgiref-3.
|
|
16
|
-
asgiref-3.
|
|
12
|
+
asgiref-3.11.0.dist-info/licenses/LICENSE,sha256=uEZBXRtRTpwd_xSiLeuQbXlLxUbKYSn5UKGM0JHipmk,1552
|
|
13
|
+
asgiref-3.11.0.dist-info/METADATA,sha256=gV4IrytPfzCXgnDhv_rM5GBoUUd_Tz-QvqZSFKEmVGs,9287
|
|
14
|
+
asgiref-3.11.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
15
|
+
asgiref-3.11.0.dist-info/top_level.txt,sha256=bokQjCzwwERhdBiPdvYEZa4cHxT4NCeAffQNUqJ8ssg,8
|
|
16
|
+
asgiref-3.11.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|