|
@@ -20,7 +20,6 @@ import gc
|
|
|
import os
|
|
|
import select
|
|
|
import socket
|
|
|
-import struct
|
|
|
import sys
|
|
|
import time
|
|
|
from collections import deque, namedtuple
|
|
@@ -41,6 +40,7 @@ from kombu.utils.functional import fxrange
|
|
|
from vine import promise
|
|
|
|
|
|
from celery.five import Counter, items, values
|
|
|
+from celery.platforms import pack, unpack, unpack_from
|
|
|
from celery.utils.functional import noop
|
|
|
from celery.utils.log import get_logger
|
|
|
from celery.worker import state as worker_state
|
|
@@ -52,13 +52,11 @@ try:
|
|
|
from _billiard import read as __read__
|
|
|
readcanbuf = True
|
|
|
|
|
|
+ # unpack_from supports memoryview in 2.7.6 and 3.3+
|
|
|
if sys.version_info[0] == 2 and sys.version_info < (2, 7, 6):
|
|
|
|
|
|
- def unpack_from(fmt, view, _unpack_from=struct.unpack_from): # noqa
|
|
|
+ def unpack_from(fmt, view, _unpack_from=unpack_from): # noqa
|
|
|
return _unpack_from(fmt, view.tobytes()) # <- memoryview
|
|
|
- else:
|
|
|
- # unpack_from supports memoryview in 2.7.6 and 3.3+
|
|
|
- unpack_from = struct.unpack_from # noqa
|
|
|
|
|
|
except ImportError: # pragma: no cover
|
|
|
|
|
@@ -70,7 +68,7 @@ except ImportError: # pragma: no cover
|
|
|
return n
|
|
|
readcanbuf = False # noqa
|
|
|
|
|
|
- def unpack_from(fmt, iobuf, unpack=struct.unpack): # noqa
|
|
|
+ def unpack_from(fmt, iobuf, unpack=unpack): # noqa
|
|
|
return unpack(fmt, iobuf.getvalue()) # <-- BytesIO
|
|
|
|
|
|
__all__ = ('AsynPool',)
|
|
@@ -252,7 +250,7 @@ class ResultHandler(_pool.ResultHandler):
|
|
|
else EOFError())
|
|
|
Hr += n
|
|
|
|
|
|
- body_size, = unpack_from(b'>i', bufv)
|
|
|
+ body_size, = unpack_from('>i', bufv)
|
|
|
if readcanbuf:
|
|
|
buf = bytearray(body_size)
|
|
|
bufv = memoryview(buf)
|
|
@@ -658,7 +656,7 @@ class AsynPool(_pool.Pool):
|
|
|
self.on_process_down = on_process_down
|
|
|
|
|
|
def _create_write_handlers(self, hub,
|
|
|
- pack=struct.pack, dumps=_pickle.dumps,
|
|
|
+ pack=pack, dumps=_pickle.dumps,
|
|
|
protocol=HIGHEST_PROTOCOL):
|
|
|
"""Create handlers used to write data to child processes."""
|
|
|
fileno_to_inq = self._fileno_to_inq
|
|
@@ -820,7 +818,7 @@ class AsynPool(_pool.Pool):
|
|
|
# inqueues are writable.
|
|
|
body = dumps(tup, protocol=protocol)
|
|
|
body_size = len(body)
|
|
|
- header = pack(b'>I', body_size)
|
|
|
+ header = pack('>I', body_size)
|
|
|
# index 1,0 is the job ID.
|
|
|
job = get_job(tup[1][0])
|
|
|
job._payload = buf_t(header), buf_t(body), body_size
|
|
@@ -1255,11 +1253,11 @@ class AsynPool(_pool.Pool):
|
|
|
return removed
|
|
|
|
|
|
def _create_payload(self, type_, args,
|
|
|
- dumps=_pickle.dumps, pack=struct.pack,
|
|
|
+ dumps=_pickle.dumps, pack=pack,
|
|
|
protocol=HIGHEST_PROTOCOL):
|
|
|
body = dumps((type_, args), protocol=protocol)
|
|
|
size = len(body)
|
|
|
- header = pack(b'>I', size)
|
|
|
+ header = pack('>I', size)
|
|
|
return header, body, size
|
|
|
|
|
|
@classmethod
|