Update Consumer.py
Browse files- Consumer.py +6 -9
Consumer.py
CHANGED
|
@@ -159,10 +159,10 @@ async def main():
|
|
| 159 |
print(f"Received task {uid}")
|
| 160 |
|
| 161 |
# Create async task
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
|
| 167 |
await asyncio.sleep(POLL_INTERVAL)
|
| 168 |
|
|
@@ -178,12 +178,9 @@ if __name__ == "__main__":
|
|
| 178 |
if loop and loop.is_running():
|
| 179 |
print("Event loop already running. Scheduling main task...")
|
| 180 |
loop.create_task(main())
|
| 181 |
-
# Note: We assume the existing loop will keep running.
|
| 182 |
-
# If this is a script that just exits, we might need loop.run_forever() if not already happening.
|
| 183 |
-
loop.run_forever()
|
| 184 |
else:
|
| 185 |
print("Starting new event loop...")
|
| 186 |
-
asyncio.run(main())
|
| 187 |
-
|
| 188 |
except KeyboardInterrupt:
|
| 189 |
print("Stopping consumer...")
|
|
|
|
| 159 |
print(f"Received task {uid}")
|
| 160 |
|
| 161 |
# Create async task
|
| 162 |
+
task = active_tasks[uid]
|
| 163 |
+
active_tasks[uid] = asyncio.create_task(process_task(uid, code))
|
| 164 |
+
if task:
|
| 165 |
+
task.cancel()
|
| 166 |
|
| 167 |
await asyncio.sleep(POLL_INTERVAL)
|
| 168 |
|
|
|
|
| 178 |
if loop and loop.is_running():
|
| 179 |
print("Event loop already running. Scheduling main task...")
|
| 180 |
loop.create_task(main())
|
|
|
|
|
|
|
|
|
|
| 181 |
else:
|
| 182 |
print("Starting new event loop...")
|
| 183 |
+
loop=asyncio.run(main())
|
| 184 |
+
loop.run_forever()
|
| 185 |
except KeyboardInterrupt:
|
| 186 |
print("Stopping consumer...")
|