Skip to content

Commit c8a62e2

Browse files
author
sergey.komissarov
committed
Allow concurrent execution for sync_to_async calls inside library.
1 parent dbda3f2 commit c8a62e2

File tree

5 files changed

+11
-5
lines changed

5 files changed

+11
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2323

2424
# Changelog
2525

26+
## [1.0.0rc6] - 2023-05-10
27+
28+
- `sync_to_async` calls inside library now runs concurrently.
29+
2630
## [1.0.0rc5] - 2023-05-05
2731

2832
WARNING: Release contains backward incompatible changes!

channels_graphql_ws/graphql_ws_consumer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ async def _on_gql_start__parse_query(
735735
"""
736736

737737
res = await channels.db.database_sync_to_async(
738-
self._on_gql_start__parse_query_sync_cached
738+
self._on_gql_start__parse_query_sync_cached, thread_sensitive=False
739739
)(op_name, query)
740740

741741
doc_ast: Optional[graphql.DocumentNode] = res[0]
@@ -994,7 +994,9 @@ def enqueue_notification(payload):
994994
if waitlist:
995995
await asyncio.wait(waitlist)
996996

997-
_deserialize = channels.db.database_sync_to_async(Serializer.deserialize)
997+
_deserialize = channels.db.database_sync_to_async(
998+
Serializer.deserialize, thread_sensitive=False
999+
)
9981000

9991001
# For each notification (event) yielded from this function the
10001002
# `_on_gql_start__subscribe` function will call subscription

channels_graphql_ws/subscription.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ async def broadcast_async(cls, *, group=None, payload=None):
197197
# Manually serialize the `payload` to allow transfer of Django
198198
# models inside `payload`, auto serialization does not do this.
199199
serialized_payload = await channels.db.database_sync_to_async(
200-
Serializer.serialize
200+
Serializer.serialize, thread_sensitive=False
201201
)(payload)
202202

203203
# Send the message to the Channels group.

example/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@
8383
}
8484
]
8585
INSTALLED_APPS: List[str] = [
86+
"daphne",
8687
"django.contrib.contenttypes",
8788
"django.contrib.sessions",
8889
"django.contrib.auth",
8990
"django.contrib.messages",
9091
"django.contrib.staticfiles",
9192
"django.contrib.admin",
92-
"daphne",
9393
"channels",
9494
]
9595
ALLOWED_HOSTS = ["*"]

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ build-backend = "poetry.core.masonry.api"
3434
# Docs: https://python-poetry.org/docs/
3535
[tool.poetry]
3636
name = "django-channels-graphql-ws"
37-
version = "v1.0.0rc5"
37+
version = "v1.0.0rc6"
3838
description = """Django Channels based WebSocket GraphQL server with Graphene-like subscriptions"""
3939
authors = ["Alexander A. Prokhorov <alexander.prokhorov@datadvance.net>"]
4040
homepage = "https://github.com/datadvance/DjangoChannelsGraphqlWs"

0 commit comments

Comments
 (0)