-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdb_queue.py
41 lines (23 loc) · 820 Bytes
/
db_queue.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import asyncio
class DBqueue:
def __init__(self):
self.queue = asyncio.Queue()
self.tasks = [] # workers task list
async def put(self,json):
self.queue.put_nowait(json) #put workload to a queue
task = asyncio.create_task(self.worker(f'worker-{i}', self.queue))
self.tasks.append(task)
#await queue.join()
async def worker(self,routine,name):
while True:
json = await self.queue.get()
await routine(json)
self.queue.task_done()
print(f'{name} did it!!')
print(f'{name} did it!!')
# class DBhandler:
# def __init__(self):
# self.loop = asyncio.get_event_loop()
# def get_a_queue(self,json):
# insert_queue.put_nowait(json)
# def worker