Fix invalid 'args' and 'kwargs' decoding in python3

When we set pass_arguments=True, we should unpickle
'args' and 'kwargs' first.

Without it '_decode_from_spooler' will fail on 'decoding' their
packed by pickle data, because pickled data has 'bytes' type.
This commit is contained in:
Yury Khalyavin
2014-10-30 18:00:56 +03:00
parent afeeecbb86
commit fe68884ea4
3 changed files with 22 additions and 7 deletions
@@ -20,8 +20,10 @@ class BitmapTest(unittest.TestCase):
spooler_handlers.controlled_task.spool(arg='barbis')
spooler_handlers.controlled_raw_task.spool(arg='alive', ghost='world')
spooler_handlers.controlled_raw_task.spool(arg='barbis')
spooler_handlers.controlled_arguments_task.spool(
{'key': 'value'}, 2, key1='value1')
for i in range(4):
for i in range(5):
uwsgi.signal_wait(20)
print("Signal received!")
@@ -6,6 +6,14 @@ import uwsgi
ghostpath = "/tmp/ghost"
@spool(pass_arguments=True)
def controlled_arguments_task(*args, **kwargs):
if args != ({'key': 'value'}, 2) or kwargs != {'key1': 'value1'}:
print("We have a problem!")
open(ghostpath, 'w').close()
uwsgi.signal(20)
@spool
def controlled_task(arguments):
if arguments['arg'] != 'alive' and 'ghost' in arguments:
+11 -6
View File
@@ -50,17 +50,22 @@ def get_free_signal():
def manage_spool_request(vars):
# To check whether 'args' is in vals or not - decode the keys first,
# because in python3 all keys in 'vals' are have 'byte' types
vars = dict((_decode1(K), V) for (K, V) in vars.items())
if 'args' in vars:
for k in ('args', 'kwargs'):
vars[k] = pickle.loads(vars.pop(k))
vars = _decode_from_spooler(vars)
f = spooler_functions[vars['ud_spool_func']]
if 'args' in vars:
args = pickle.loads(vars.pop('args'))
kwargs = pickle.loads(vars.pop('kwargs'))
ret = f(*args, **kwargs)
ret = f(*vars['args'], **vars['kwargs'])
else:
ret = f(vars)
if not 'ud_spool_ret' in vars:
return ret
return int(vars['ud_spool_ret'])
return int(vars.get('ud_spool_ret', ret))
def postfork_chain_hook():