shoom013 commited on
Commit
4b4b7ee
·
verified ·
1 Parent(s): 94691c4

Update Consumer.py

Browse files
Files changed (1) hide show
  1. Consumer.py +5 -2
Consumer.py CHANGED
@@ -152,10 +152,13 @@ async def main():
152
  print(f"Received task {uid}")
153
 
154
  # Create async task
 
 
 
155
  task = asyncio.create_task(process_task(uid, code))
156
  active_tasks[uid] = task
157
- if uid in active_tasks:
158
- active_tasks[uid].cancel()
159
 
160
  await asyncio.sleep(POLL_INTERVAL)
161
 
 
152
  print(f"Received task {uid}")
153
 
154
  # Create async task
155
+ taskold = None
156
+ if uid in active_tasks:
157
+ taskold = active_tasks[uid]
158
  task = asyncio.create_task(process_task(uid, code))
159
  active_tasks[uid] = task
160
+ if taskold and taskold.is_running():
161
+ taskold.cancel()
162
 
163
  await asyncio.sleep(POLL_INTERVAL)
164