You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to build some code that runs saved python scripts on demand. As such, the requests are ran in spawned tokio tasks. All of the documentation I could find shows running asynchrounous Python code in the main tokio task in the main function. Here is a minimal example that I tried, but I get behavior that is difficult to understand.
It's essentially the example here just inside tokio::spawn.
Output
<sys>:0: RuntimeWarning: coroutine 'sleep' was never awaited
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
Traceback (most recent call last):
File "/opt/homebrew/Cellar/[email protected]/3.13.3/Frameworks/Python.framework/Versions/3.13/lib/python3.13/asyncio/base_events.py", line 719, in run_until_complete
return future.result()
~~~~~~~~~~~~~^^
RuntimeError: no running event loop
There is more output, but I think this is the salient error.
Is this expected behavior? I read the section on how asyncio wants the main thread, but does it also need to be initialized per tokio worker thread? Some architectural context would be nice, or a specific design pattern. If there are changes required to support this, I'm happy to give them a shot.
*Updated to be a more minimal example.
The text was updated successfully, but these errors were encountered:
Hm, I tried something like that, but that only works if the python module and locals are constructed on the main thread. I want something where more like my updated example above.
Uh oh!
There was an error while loading. Please reload this page.
I'm trying to build some code that runs saved python scripts on demand. As such, the requests are ran in spawned
tokio
tasks. All of the documentation I could find shows running asynchrounous Python code in the maintokio
task in the main function. Here is a minimal example that I tried, but I get behavior that is difficult to understand.Minimal Example
It's essentially the example here just inside
tokio::spawn
.Output
There is more output, but I think this is the salient error.
Is this expected behavior? I read the section on how
asyncio
wants the main thread, but does it also need to be initialized pertokio
worker thread? Some architectural context would be nice, or a specific design pattern. If there are changes required to support this, I'm happy to give them a shot.*Updated to be a more minimal example.
The text was updated successfully, but these errors were encountered: