error_callback when using apply_async in python 2.7
lizaclark opened this issue · comments
When I call rvic.parameters.parameters
with multiple cores in Python 2.7.11, I get the following error:
INFO:parameters>> On Outlet 1 of 1
ERROR:write>> Traceback (most recent call last):
ERROR:write>> File "run_rvic.py", line 62, in
ERROR:write>> main()
ERROR:write>> File "run_rvic.py", line 56, in main
ERROR:write>> rvic.parameters.parameters(param_cfg_name, numofproc=cores)
ERROR:write>> File "/d6/eclark/miniconda2/envs/otl_env/lib/python2.7/site-packages/rvic-1.1.0-py2.7-linux-x86_64.egg/rvic/parameters.py", line 73, in parameters
ERROR:write>> error_callback=error)
ERROR:write>> TypeError
ERROR:write>> :
ERROR:write>> apply_async() got an unexpected keyword argument 'error_callback'
Apparently error_callback
is not a keyword option for apply_async
in python 2 (ref). In this case, it looks like nothing happens if there is an error; the callback just isn't called. I can think of 3 options for how to handle this:
- Put in a python version check that disables multiprocessing for python 2.
- Make a function that only uses
error_callback
if user is using python 3. Set up an error check in thestat
return value ofapply_async
to show if the job completed or not. The problem, of course, being that you don't get the error code fromgen_uh_run
. - Add something like this traceback function to
gen_uh_run
.
My vote is for 1) since there is no good reason to keep everything compatible with python 2.
I think we can just leave out the error_callback
argument in python 2.7.
Some psudo code:
def _make_async_kwargs():
kwargs = dict(callback=store_result)
if py3:
kwargs['error_callback'] = error
return kwargs
kwargs = _make_async_kwargs()
for i, (key, outlet) in enumerate(iteritems(outlets)):
log.info('On Outlet #%s of %s', i + 1, len(outlets))
stat = pool.apply_async(gen_uh_run,
(uh_box, fdr_data, fdr_vatts,
dom_data, outlet, config_dict,
directories),
**kwargs)
@lizaclark - do you know if stat.get()
will raise an error in Python 2?