I want to start an asynchronous task/thread that is classed based. Like an class variable, meaning it is accessible to each instance of the class.
I tried to create a separate class which uses asyncio.
class yahoo_connection:
def __init__(self):
self.list_of_tick=[]
self.format="%H %M %S"
self.running=True
asyncio.create_task(self.const_thread())
async def const_thread(self):
while self.running==True:
print("current list: ",self.list_of_tick)
if len(self.list_of_tick)!=0:
idx=np.random.randint(len(self.list_of_tick)+1)
self.format=self.list_of_tick[idx]
await asyncio.sleep(3.5)
So this is the class that I planned to initialize as the class thread of my original class. However this code does not work.
I want to able to modify the self.list_of_tick in each instance the class that uses the class yahoo_connection as the class asynchronous thread.