Skip to content
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

Exception when num_workers > 0 on Windows, works on linux #5

Open
jfb54 opened this issue Mar 13, 2021 · 4 comments
Open

Exception when num_workers > 0 on Windows, works on linux #5

jfb54 opened this issue Mar 13, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@jfb54
Copy link

jfb54 commented Mar 13, 2021

On Windows 10, if num_workers > 0, you get the following exception:
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\multiprocessing\popen_spawn_win32.py", line 65, in init
reduction.dump(process_obj, to_child)
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\multiprocessing\reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)
TypeError: can't pickle generator objects
python-BaseException
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 115, in _main
self = reduction.pickle.load(from_parent)
EOFError: Ran out of input
python-BaseException

@mboudiaf
Copy link
Owner

I believe this is due to the way my datasets are instantiated. For instance, when instantiating an EpisodicDataset, it creates a list of generators at

self.class_datasets = [cycle(dataset) for dataset in class_datasets]
. The problem is that generator objects cannot be pickled, which is exactly what he seems to be doing on Windows when multiprocessing is activated (i.e num_workers > 0). I suspect the way it works is that the dataset is created on the main worker, and then pickled for other processes to load.

So the workaround would be to remove this line and find a way to create the generator in the iter function (only when needed of course) and not the init . This should be doable with a try except. Given that I do not have Windows 10, I will unfortunately be unable to reproduce this error, but I would be happy to help debug it further :)

@jfb54
Copy link
Author

jfb54 commented Mar 15, 2021

Thanks for clarifying. I have a linux machine as well, so I am not blocked. I may try your suggestion.

mboudiaf added a commit that referenced this issue Apr 1, 2021
…licate data when num_workers > 0 + attempt to solve the problem of generator pickling #5
@mboudiaf
Copy link
Owner

mboudiaf commented Apr 1, 2021

I have tried to fix the issue by implementing the initial workaround I proposed earlier. Please let me know if that fixes the issue on Windows ! Thanks in advance :)

@jfb54
Copy link
Author

jfb54 commented Apr 2, 2021

Thanks for working on this. Unfortunately, there is still an issue on Windows, with num_workers > 0, there is a new error:
ForkingPickler(file, protocol).dump(obj)
AttributeError: Can't pickle local object 'Reader.construct_class_datasets..decode_image'

@mboudiaf mboudiaf added the bug Something isn't working label Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants