Error on Pickling Error Message: Timeout.__init__() missing 1 required positional argument: 'lock_file'
#202
Labels
Timeout.__init__() missing 1 required positional argument: 'lock_file'
#202
Description
If a
filelock.Timeout()
occurs, the resulting error does not pickle correctly.This is a problem, because the module
concurrent.futures
assumes exceptions are pickled correctly, so they can besent back to the main process.
filelock: 3.10.0
Python: 3.11.2
Steps to Reproduce
Run the following file
It will fail with traceback:
The message
TypeError: Timeout.__init__() missing 1 required positional argument: 'lock_file'
is very cryptic, but after some investigation, it appears this issue is caused by howfilelock._error.Timeout
is implemented:https://github.com/tox-dev/py-filelock/blob/b1b3e87a2eefadb0fd0a785c986c6a9c9cea8f07/src/filelock/_error.py#L4-L13
The issue seems to be that, when pickled, (via
__reduce__
) the default behavior does not account for the custom "lock_file" format.This can be shown by the example:
Expected Behavior
The
filelock.Timeout
should pickle correctly, allowing the exception to be properly handled byconcurrent.futures
.There should also be a test case to make sure the exception pickling works.
Suggested Change
I suggest the following Timeout class be adopted:
This error makes use of OSError's filename argument, as the general method of marking the file associated with the error. A property method is added so the old name
lock_file
will still work.By providing the explicit
__reduce__()
method, the error is corrected. (Typing hint is based on discussion here: python/typeshed#3452)The text was updated successfully, but these errors were encountered: