T
T
tamerlanlarsanov2021-09-27 14:45:36
Python
tamerlanlarsanov, 2021-09-27 14:45:36

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

1 answer(s)
D
Dmitry, 2021-09-27
@dmtrrr

https://docs.python.org/3/library/asyncio-dev.html...
"trade" is a very strange pronunciation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question