parallel in win notebook #294
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It is very tricky to run multiprocessing in notebook on Windows.
First, The multiprocessing can only be executed in Top-level script environment, that is in the scope of
if __name__ == "__main__":.Otherwise, notebook will hang due to reimporting modules.
Second, all functions, objects used in the subprocesses must be imported from separate module, not from the main module. Because the main module in newly spawned process in notebook is a empty module. If something used in subprocess but is defined in main module, it will throw
AtrributeError: Can't get attribute ....Thirdly, we have to import libraries in the function. otherwise, we'll get an exception that
module isn't defined. https://github.com/mszhanyi/fastcore/blob/e1536a5dddbde477e84dfa57e372e4f481353087/fastcore/parallel.py#L128Lastly, lamda function couldn't be passed to subprocess.
This PR is to provide a example on how to run fastcore.parallel in notebook on Windows.
As for dataloader, It is much harder because there are multiple functions and objects send to workers. code would become very ugly.
@jph00 @maxluk