Initial work on fix for #424 - TypeError: can't pickle _thread.lock objects.

Made `Broker` and `Queue` classes pickable which fixes the the problem with new default `spawn` proces start method.
This commit is contained in:
ihuk
2020-10-14 22:21:40 +02:00
parent 22b6f8ec5a
commit 8b3d6b7d2a
3 changed files with 24 additions and 2 deletions
+8
View File
@@ -13,6 +13,14 @@ class Broker:
self.cache = self.get_cache()
self._info = None
def __getstate__(self):
return self.list_key, self._info
def __setstate__(self, state):
self.list_key, self._info = state
self.connection = self.get_connection(self.list_key)
self.cache = self.get_cache()
def enqueue(self, task):
"""
Puts a task onto the queue
+9 -1
View File
@@ -12,7 +12,15 @@ from time import sleep
import arrow
# Django
from django import db
from django import db, core
from django.apps.registry import apps
try:
apps.check_apps_ready()
except core.exceptions.AppRegistryNotReady:
import django
django.setup()
from django.conf import settings
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
+7 -1
View File
@@ -54,9 +54,15 @@ class Queue(multiprocessing.queues.Queue):
super(Queue, self).__init__(
*args, ctx=multiprocessing.get_context(), **kwargs
)
self.size = SharedCounter(0)
def __getstate__(self):
return super(Queue, self).__getstate__() + (self.size, )
def __setstate__(self, state):
super(Queue, self).__setstate__(state[:-1])
self.size = state[-1]
def put(self, *args, **kwargs):
super(Queue, self).put(*args, **kwargs)
self.size.increment(1)