How to run async task inside subinterpreter? #904
Answered
by
agronholm
baseplate-admin
asked this question in
Q&A
-
|
Hi, import anyio
async def hello_world():
print("Hello, world!")
await anyio.sleep(1)
print("Goodbye, world!")
async def main():
anyio.to_interpreter.run_sync(hello_world)
anyio.run(main)But this is not working as expected, is async under subinterpreter under works? Or what i asked here is not possible. Thanks in advance |
Beta Was this translation helpful? Give feedback.
Answered by
agronholm
Apr 2, 2025
Replies: 1 comment 5 replies
-
|
Why would you want to do something like this? The whole point of subinterpreters is to allow taking advantage of multiple CPU cores while running CPU intensive synchronous Python code. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perhaps you'd like to use InterpreterPoolExecutor to run separate event loops then? I don't think the AnyIO facilities are the right solution for you. Also be aware of the WIP nature of the subinterpreters interface in Python.