async def some_callback(args):
await some_function()
def between_callback(args):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(some_callback(args))
loop.close()
_thread = threading.Thread(target=between_callback, args=("some text"))
_thread.start()
import asyncio
async def get_some_values_from_io():
# Some IO code which returns a list of values
...
vals = []
async def fetcher():
while True:
io_vals = await get_some_values_from_io()
for val in io_vals:
vals.append(io_vals)
async def monitor():
while True:
print (len(vals))
await asyncio.sleep(1)
async def main():
t1 = asyncio.create_task(fetcher())
t2 = asyncio.create_task(monitor())
await asyncio.gather(t1, t2)
asyncio.run(main())
import asyncio
async def get_data_from_io():
...
async def process_data(data):
...
async def main():
while true:
data = await get_data_from_io()
await process_data(data)
asyncio.run(main())