Answer the question
In order to leave comments, you need to log in
Why can't I add tasks to asyncio from the threading module trade?
I want to make a trade with which I can add tasks to the asinka event loop, but for some reason nothing happens after adding the task. The value of the variable f remains zero. I don't get any errors, the trade works, the check and func commands work, but nothing happens after the func command is executed. Help me to understand.
import threading, asyncio
f = 0
async def start():
t2 = threading.Thread(target = cmd, args = (loop,)).start()
pass
async def func():
print('start')
global f
while True:
await asyncio.sleep(5)
f += 1
def cmd(loop):
while True:
c = input()
if c == 'func':
loop.create_task(func())
elif c == 'check':
print(f)
loop = asyncio.get_event_loop()
loop.create_task(start())
loop.run_forever()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question