From b91b89a183db70f0ca32b1e49eb05a02f9dce0c9 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Sat, 26 Jul 2014 11:53:31 +0200 Subject: [PATCH] Use highest pickle protocol version to serialize job data. --- rq/job.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/rq/job.py b/rq/job.py index 362265d..c757a49 100644 --- a/rq/job.py +++ b/rq/job.py @@ -3,8 +3,9 @@ from __future__ import (absolute_import, division, print_function, unicode_literals) import inspect -from uuid import uuid4 import warnings +from functools import partial +from uuid import uuid4 from rq.compat import as_text, decode_redis_hash, string_types, text_type @@ -14,9 +15,14 @@ from .local import LocalStack from .utils import import_attribute, utcformat, utcnow, utcparse try: - from cPickle import loads, dumps, UnpicklingError + import cPickle as pickle except ImportError: # noqa - from pickle import loads, dumps, UnpicklingError # noqa + import pickle + +# Serialize pickle dumps using the highest pickle protocol (binary, default +# uses ascii) +dumps = partial(pickle.dumps, protocol=pickle.HIGHEST_PROTOCOL) +loads = pickle.loads def enum(name, *sequential, **named): @@ -47,7 +53,7 @@ def unpickle(pickled_string): """ try: obj = loads(pickled_string) - except (Exception, UnpicklingError) as e: + except Exception as e: raise UnpickleError('Could not unpickle.', pickled_string, e) return obj