Closed klementng closed 4 months ago
@klementng Thanks for the report, I'll look into it.
The following is most likely what is going:
FormatAutodetectionError("content", ['srt','ass'])
FormatAutodetectionError("content")
This issue only occured in the versions 1.7.0 onwards where it seem that all the exceptions class for pysub2 was rewritten
A dirty hack is to simply add a default argument to the exception which will fix the issue but causes the error message to be misleading
class FormatAutodetectionError(Pysubs2Error):
....
def __init__(self, content: str, formats: List[str] = []) -> None:
self.content = content
self.formats = formats
if not formats:
msg = "No suitable formats"
else:
msg = f"Multiple suitable formats ({formats!r})"
super().__init__(msg)
New test code:
def _error_callback(error):
print(error) # it now misleading
# The full trackback will shows the correct error & the misleading one as well
# print("\n\n\n")
# traceback.print_exception(type(error), error, error.__traceback__)
def _f():
raise pysubs2.FormatAutodetectionError("", ["srt", "ass"])
with multiprocessing.Pool(4) as pool:
for _ in range(2):
pool.apply_async(
_f,
error_callback=_error_callback,
)
pool.close()
pool.join()
which outputs
No suitable formats
No suitable formats
Ultimately, this seem to be an issue with the multiprocessing library where it expect all the exception to have same identity for the init function as the base exception class
Please upgrade to version 1.7.3, it should be fixed :)
In my own project, I've been running into issues when using the python multiprocessing library in together with pysub2.
From my observations, when the FormatAutodetectionError exception is raised, the whole multiprocessing crashes with the following trackback
Upon further investigation, the issues seem to be caused by the transferring of the exception from the thread to the main program where the exception which causes in the formats arg being lost / not passed.
Reproducible code example
Related stackoverflow issue: https://stackoverflow.com/questions/70883678/python-multiprocessing-get-hung
My fix for this issue is to simply passing the ext into the _format kwargs to prevent the autodetection function from running