I'm trying to create a print function that keeps printing, for example, 'Hello World', while another function (called miner) is running in parallel, and both functions must end at the same time.
This is for a real-time cost measurer for bitcoin mining that I'm working on.
I found that python as asyncio and tried to use it, however I couldn't get the print function to stop at the same time the miner function ends. The timer function printed once and waited for the miner function.
import asyncio
import time
from datetime import datetime
class Test2:
async def miner(self):
await asyncio.sleep(5)
return 0
async def timer(self):
while True:
print("\n Hello World \n")
time.sleep(1)
t2 = Test2()
loop = asyncio.get_event_loop()
loop.run_until_complete(asyncio.gather(t2.miner(), t2.timer()))
I tried concurrent tasks, but both function does not run in parallel (timer and miner). Could you show me a way to solve this? Thank you!