From 507636716856203d096438653419b1fe0054dab5 Mon Sep 17 00:00:00 2001 From: ihuk Date: Fri, 16 Oct 2020 18:40:26 +0200 Subject: [PATCH] More work on fix for #424 - TypeError: can't pickle _thread.lock objects. AWS and Mongo brockers should be pickeled correctly now. --- django_q/brokers/aws_sqs.py | 5 +++++ django_q/brokers/mongo.py | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/django_q/brokers/aws_sqs.py b/django_q/brokers/aws_sqs.py index 1a6deda..a666934 100644 --- a/django_q/brokers/aws_sqs.py +++ b/django_q/brokers/aws_sqs.py @@ -10,6 +10,11 @@ class Sqs(Broker): super(Sqs, self).__init__(list_key) self.queue = self.get_queue() + def __setstate__(self, state): + super(Sqs, self).__setstate__(state) + self.sqs = None + self.queue = self.get_queue() + def enqueue(self, task): response = self.queue.send_message(MessageBody=task) return response.get("MessageId") diff --git a/django_q/brokers/mongo.py b/django_q/brokers/mongo.py index a130113..a4857bd 100644 --- a/django_q/brokers/mongo.py +++ b/django_q/brokers/mongo.py @@ -19,6 +19,10 @@ class Mongo(Broker): super(Mongo, self).__init__(list_key) self.collection = self.get_collection() + def __setstate__(self, state): + super(Mongo, self).__setstate__(state) + self.collection = self.get_collection() + @staticmethod def get_connection(list_key: str = Conf.PREFIX) -> MongoClient: return MongoClient(**Conf.MONGO)