Skip to content

Executing functions with keyword-only arguments raises an errorr #208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lesteve opened this issue Apr 23, 2019 · 3 comments
Closed

Executing functions with keyword-only arguments raises an errorr #208

lesteve opened this issue Apr 23, 2019 · 3 comments

Comments

@lesteve
Copy link
Member

lesteve commented Apr 23, 2019

Related joblib bug: joblib/joblib#863

from loky import get_reusable_executor


def func_with_kw_only_args(a, *, b=1):
    return a + b


executor = get_reusable_executor(max_workers=2)

res = executor.submit(func_with_kw_only_args, 1)
print("Got results:", res.result())

Traceback:

---------------------------------------------------------------------------
_RemoteTraceback                          Traceback (most recent call last)
_RemoteTraceback: 
"""
Traceback (most recent call last):
  File "/home/local/lesteve/dev/loky/loky/process_executor.py", line 418, in _process_worker
    r = call_item()
  File "/home/local/lesteve/dev/loky/loky/process_executor.py", line 272, in __call__
    return self.fn(*self.args, **self.kwargs)
TypeError: func_with_kw_only_args() missing 1 required keyword-only argument: 'b'
"""

The above exception was the direct cause of the following exception:

TypeError                                 Traceback (most recent call last)
<ipython-input-12-ec20eabd887b> in <module>
      9 
     10 res = executor.submit(func_with_kw_only_args, 1)
---> 11 print("Got results:", res.result())
     12 

/home/local/lesteve/miniconda3/lib/python3.7/concurrent/futures/_base.py in result(self, timeout)
    430                 raise CancelledError()
    431             elif self._state == FINISHED:
--> 432                 return self.__get_result()
    433             else:
    434                 raise TimeoutError()

/home/local/lesteve/miniconda3/lib/python3.7/concurrent/futures/_base.py in __get_result(self)
    382     def __get_result(self):
    383         if self._exception:
--> 384             raise self._exception
    385         else:
    386             return self._result

TypeError: func_with_kw_only_args() missing 1 required keyword-only argument: 'b'
@lesteve
Copy link
Member Author

lesteve commented Apr 23, 2019

Note: putting the function with keyword-only arguments in a module works, so I am guessing the bug lies in the magic to pickle the __main__ namespace.

@lesteve
Copy link
Member Author

lesteve commented Apr 23, 2019

I opened a bug in cloudpickle since this is very likely where the root problem lies: cloudpipe/cloudpickle#263

@ogrisel
Copy link
Contributor

ogrisel commented Jun 7, 2019

cloudpipe/cloudpickle#264 was merged and released in cloudpickle 1.2.0, so I assume this can be closed as well.

@ogrisel ogrisel closed this as completed Jun 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants