Commit f4cf5aff authored by Kirill Smelkov's avatar Kirill Smelkov

Y wcfs: multiprocessing: Allow SubProcess to be used with plain functions directly

Sometimes it is useful to run just f(*argv, **kw) instead of f(cin,
cout, *argv, **kw). For example for upcoming `wcfs status` we will need
to run os.stat(".wcfs/zurl") and similar things. Add low-level
flag-parameter to omit passing cin and cout to the called function.
parent cd2ee503
...@@ -73,12 +73,14 @@ class SubProcess(object): ...@@ -73,12 +73,14 @@ class SubProcess(object):
sys.stdout = open(os.devnull, 'w') sys.stdout = open(os.devnull, 'w')
argv = cin.recv() argv = cin.recv()
kw = cin.recv() kw = cin.recv()
if not kw.pop('_nocincout', False):
argv = (cin, cout) + argv
modname, funcname = funcpath.rsplit('.', 1) modname, funcname = funcpath.rsplit('.', 1)
mod = importlib.import_module(modname) mod = importlib.import_module(modname)
f = getattr(mod, funcname) f = getattr(mod, funcname)
procname = kw.pop('_procname', funcpath) procname = kw.pop('_procname', funcpath)
try: try:
f(cin, cout, *argv, **kw) f(*argv, **kw)
_ = 'END' _ = 'END'
except BaseException as exc: except BaseException as exc:
# dump traceback so it appears in the log because Traceback objects are not picklable # dump traceback so it appears in the log because Traceback objects are not picklable
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment