Use highest pickle protocol version to serialize job data.

main
Vincent Driessen 11 years ago
parent 79db282879
commit b91b89a183

@ -3,8 +3,9 @@ from __future__ import (absolute_import, division, print_function,
unicode_literals) unicode_literals)
import inspect import inspect
from uuid import uuid4
import warnings import warnings
from functools import partial
from uuid import uuid4
from rq.compat import as_text, decode_redis_hash, string_types, text_type 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 from .utils import import_attribute, utcformat, utcnow, utcparse
try: try:
from cPickle import loads, dumps, UnpicklingError import cPickle as pickle
except ImportError: # noqa 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): def enum(name, *sequential, **named):
@ -47,7 +53,7 @@ def unpickle(pickled_string):
""" """
try: try:
obj = loads(pickled_string) obj = loads(pickled_string)
except (Exception, UnpicklingError) as e: except Exception as e:
raise UnpickleError('Could not unpickle.', pickled_string, e) raise UnpickleError('Could not unpickle.', pickled_string, e)
return obj return obj

Loading…
Cancel
Save