-
Notifications
You must be signed in to change notification settings - Fork 56
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
Remove asgiref dependency from non Django code #1226
base: v3
Are you sure you want to change the base?
Changes from all commits
4d501c1
23ae905
41517f7
457a762
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -234,7 +234,7 @@ async def ensure_async() -> Callable[..., Awaitable]: | |
if inspect.iscoroutinefunction(task.func): | ||
await_func = task | ||
else: | ||
await_func = functools.partial(utils.sync_to_async, task) | ||
await_func = functools.partial(asyncio.to_thread, task) | ||
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. It will be interesting to discover if doing that causes issues with Django applications (https://docs.djangoproject.com/en/5.1/topics/async/#async-safety). Also, according to https://docs.djangoproject.com/en/5.1/topics/async/#sync-to-async , the use of 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.
I don't think so, as the worker manages its own connections (independent of Django), and only the user code would use Django connections. 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. I was referring to the user code (the task implementation) that is being wrapped here. What happens then when the user code uses Django connections? 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. From my understanding, it shouldn't matter if the Django connection wasn't initially created in the main thread but directly in the user thread. There is also no request/response cycle like in a Django view that messes around with those connections. And as you already recognized, our previous 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. Ah yes, as long as we don't try to support 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. Yes, and I also think that using |
||
|
||
job_args = [context] if task.pass_context else [] | ||
task_result = await await_func(*job_args, **job.task_kwargs) | ||
|
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.
I am not sure if this statement is still valid.