Skip to content

Conversation

@mszhanyi
Copy link
Contributor

@mszhanyi mszhanyi commented Feb 23, 2021

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#L128

Lastly, 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

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@jph00
Copy link
Contributor

jph00 commented May 4, 2021

Thanks @mszhanyi - sorry hadn't noticed this wasn't merged yet

@jph00 jph00 merged commit 915bd93 into AnswerDotAI:master May 4, 2021
@renato145
Copy link
Contributor

I noticed that now parallel fails with partial functions.
parallelable checks f.__module__ which partial functions don't have.

@jph00
Copy link
Contributor

jph00 commented May 10, 2021

Thanks @renato145 . @mszhanyi is this something you might be able to resolve? I guess if it's partial, or for whatever reason __module__ isn't available, we should just assume it's not Windows.

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

Successfully merging this pull request may close these issues.

3 participants