komuw / wiji

Wiji is an asyncio distributed task processor/queue.
MIT License
4 stars 1 forks source link

check if concurrency bug if things bound to self(task) #79

Open komuw opened 5 years ago

komuw commented 5 years ago

the bug exists

class PrintTask(BaseTask):
    queue_name = "PrintTaskQueue"

    async def run(self, *args, **kwargs):
        print("\n\n\t id:: ", id(self))
     id::  140151858981912
     id::  140151858981912
     id::  140151858981912
komuw commented 5 years ago

this fixes it;

diff --git a/wiji/worker.py b/wiji/worker.py
index 4a0f08d..1e2aa7b 100644
--- a/wiji/worker.py
+++ b/wiji/worker.py
@@ -158,7 +158,10 @@ class Worker:
         monotonic_start = time.monotonic()
         process_time_start = time.process_time()
         try:
-            return_value = await self.the_task.run(*task_args, **task_kwargs)
+            import copy
+
+            tt = copy.deepcopy(self.the_task)
+            return_value = await tt.run(*task_args, **task_kwargs)
             if self.the_task.the_chain and not self.the_task._RETRYING:
                 # enqueue the chained task using the return_value
                 await self.the_task.the_chain.delay(return_value)
komuw commented 5 years ago

also see; https://gist.github.com/komuw/e202c2f1405c9ff0d709abfe4466c4a3