tristandeleu / pytorch-maml-rl

Reinforcement Learning with Model-Agnostic Meta-Learning in Pytorch
MIT License
827 stars 158 forks source link

Questions about the MultiTaskSampler #44

Closed chencsgit closed 4 years ago

chencsgit commented 4 years ago

Hello,

Thanks for sharing the code.

I'm trying to put train.py and test.py into one file, which is important for me to do further work.

However, when I use sampler = MultiTaskSampler(...) the second time, it will stop at https://github.com/tristandeleu/pytorch-maml-rl/blob/243214b17da2ebfa152bba784778884b46a7e349/maml_rl/samplers/multi_task_sampler.py#L138-L143 in the multi_task_sampler.py.

It's easy to reproduce this problem, if you copy the code https://github.com/tristandeleu/pytorch-maml-rl/blob/243214b17da2ebfa152bba784778884b46a7e349/train.py#L47-L83 to the end of 'main' function where use it second time.

I think the problem may be about deadlock with multiprocessing module. However, I‘ve searched and tried many solution like gc and threading in stackoverflow, and I couldn't fix the problem.

What could be the problem?

Thank you so much if you can provide any help.

tristandeleu commented 4 years ago

Hi, I'm really sorry for the late reply, I must have missed this issue.

One problem I can see is that in train.py I don't close the sampler properly (mainly because since the processes are in daemon=True, if it reaches the end of the script the sampler will join the processes on its own). Maybe you can try adding sampler.close() between the first and second block.

chencsgit commented 4 years ago

Thanks very much!