DeepReinforcementLearning/DeepReinforcementLearningInAction

Chapter 5: undying error when I run multiprocess code in Jupyter

Opened this issue · 2 comments

When I copy code in List 5.1 and run in jupyter, it always tells me this:

Can't get attribute 'square' on <module 'main' (built-in)>

According to what I have found in Google, it seems that the code needs to be titled:

if name =='main':

but this way only works in Spyder and Pycharm.

So I wanna know how you guys tackle it.

Grateful to hear any suggestions!

Had the same issue, this is because multiprocessing does not work natively inside a Jupyter notebook. For details see this StackOverflow discussion (specifically Eden Trainor's answer):
https://stackoverflow.com/questions/48846085/python-multiprocessing-within-jupyter-notebook

Apparently someone has created a similar library to multiprocessing called multiprocess which works inside jupyter notebooks. However, I suggest the authors (@azai91) either put a !pip install multiprocess in the notebook for this, or add a comment saying to run it from an IDE like Spyder. Since the multiprocess library has its own problems (had to re-import numpy inside the process) probably would go for the latter option.

thanks for the link you provide
solved my question