-
Notifications
You must be signed in to change notification settings - Fork 972
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
Avoid deadlock in event start #322
Conversation
2697eaa
to
439dec0
Compare
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.
Good if that fixes an issue.
It looks like a very weird approach to me though, because:
- It doesn't really make sense to run an event loop for just one function;
- I don't understand, as a
run_sync()
user, how do I know if I should passnew_loop=True
ornew_loop=False
? Am I supposed to try one, and if that doesn't work, try the other one? My point being that the event loop handling probably shouldn't be the responsibility of the API user.
439dec0
to
d329739
Compare
|
fbf2667
to
02cb0b0
Compare
src/pyproject.toml
Outdated
@@ -61,7 +61,7 @@ types-requests = "^2.31.0.2" | |||
types-aiofiles = "^23.1.0.5" | |||
|
|||
[tool.mypy] | |||
python_version = "3.8" | |||
python_version = "3.10" |
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.
why are we bumping the ci python version?
src/chainlit/sync.py
Outdated
if threading.current_thread() == threading.main_thread(): | ||
return sync(co) | ||
else: | ||
if not main_thread: | ||
return asyncio.run(co) |
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.
why do we use asyncio.run here instead of sync()? Also the main_thread parameter naming might be confusing since we check threading.current_thread() == threading.main_thread()
in the condition above
When using streaming, the main event loop is blocked to await tokens, if we try to execute a function (Message.send() here) in the same event loop, it leads to a deadlock. Adding a new_loop parameter to the run_sync function allows to create a new event loop in the current Thread and allows to send a Message during a stream.
02cb0b0
to
2e0efa3
Compare
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 like force_new_loop
better 👍
When using streaming, the main event loop is blocked to await tokens, if we try to execute a function (
Message.send()
here) in the same event loop, it leads to a deadlock.Adding a
new_loop
parameter to therun_sync
function allows to create a new event loop in the current Thread and allows to send a Message during a stream.