FIXME
Project description
django_threaded_sync_to_async
FIXME add description
Executor
Under executor context, Executor
replaces sync_to_async
calls to sync_to_async(thread_sensitive=None, executor=...)
, effectively allowing Django to make calls to database concurrently:
async with django_threaded_sync_to_async.Executor(thread_name_prefix="thread", max_workers=3) as executor:
a = asgiref.sync.sync_to_async(long_call)(1)
b = asgiref.sync.sync_to_async(long_call)(2)
c = asgiref.sync.sync_to_async(long_call)(3)
d = asgiref.sync.sync_to_async(long_call)(4)
await asyncio.gather(a, b, c, d)
SharedExecutor
Maintains global dictionary of executors (concurrent.futures.ThreadPoolExecutor
) accessed by name and allows to limit utilization of executor for a single context.
@django_threaded_sync_to_async.SharedExecutor("common", max_workers=3, max_tasks=2)
def operations():
a = asgiref.sync.sync_to_async(long_call)(1)
b = asgiref.sync.sync_to_async(long_call)(2)
c = asgiref.sync.sync_to_async(long_call)(3)
d = asgiref.sync.sync_to_async(long_call)(4)
await asyncio.gather(a, b, c, d)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for django_threaded_sync_to_async-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | af9f2d1398d5fed9fa807cd80f55cfbf315d6d07be9581b8f74dc89ad425aeb2 |
|
MD5 | 367c399388b508640d6ec74757a017aa |
|
BLAKE2b-256 | 2fc90f38fc941a91925379f2665a6a450e095eb1a7f2827b607bb4cbb19f4a88 |