0

I'm new to coroutines in python but I know in lua you would do this to create one

coroutine.wrap(function()
 while true do
 end
end)()

But I dont know how I would do this python.

I tried using this code which included a function from the slp_coroutine library which didnt work

import slp_coroutine
def test():
    while True:
        print("hi")
        time.sleep(3)

r = slp_coroutine.await_coroutine(test())

and I also tried this and it also didnt work.

async def test():
    while True:
        print("hi")
        await asyncio.sleep(3)

asyncio.run(test())
  • If you just want threads, that is what `threading` is there for. In the Python ecosystem, an explicit "coroutine" is usually used for *very* high concurrency - some hundred to several thousands of tasks. – MisterMiyagi Apr 02 '22 at 05:49
  • This [link](https://stackoverflow.com/q/2846653/4897206) might help you. – Ashutosh Kumar Apr 02 '22 at 06:12

0 Answers0