Repository: chainer/chainer

Issue:
ChainerMN's ImageNet example is broken because of update in pickle module
* Conditions
<!-- If you're using Chainer 4.0+, you can also get this information by typing `python -c 'import chainer; chainer.print_runtime_info()'. -->
  - Chainer >= 5.0.0

* Code to reproduce
The ImageNet example on Python >= 3.6

```
import multiprocessing
p = multiprocessing.Process(target=lambda *x: x, args=())
p.start()
```

* Error messages, stack traces, or logs

```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/kfukuda/.pyenv/versions/anaconda3-4.3.1/lib/python3.6/multiprocessing/process.py", line 105, in start
    self._popen = self._Popen(self)
  File "/home/kfukuda/.pyenv/versions/anaconda3-4.3.1/lib/python3.6/multiprocessing/context.py", line 223, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "/home/kfukuda/.pyenv/versions/anaconda3-4.3.1/lib/python3.6/multiprocessing/context.py", line 291, in _Popen
    return Popen(process_obj)
  File "/home/kfukuda/.pyenv/versions/anaconda3-4.3.1/lib/python3.6/multiprocessing/popen_forkserver.py", line 35, in __init__
    super().__init__(process_obj)
  File "/home/kfukuda/.pyenv/versions/anaconda3-4.3.1/lib/python3.6/multiprocessing/popen_fork.py", line 20, in __init__
    self._launch(process_obj)
  File "/home/kfukuda/.pyenv/versions/anaconda3-4.3.1/lib/python3.6/multiprocessing/popen_forkserver.py", line 47, in _launch
    reduction.dump(process_obj, buf)
  File "/home/kfukuda/.pyenv/versions/anaconda3-4.3.1/lib/python3.6/multiprocessing/reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
_pickle.PicklingError: Can't pickle <function <lambda> at 0x7fb633f35e18>: attribute lookup <lambda> on __main__ failed
```
For details, see https://docs.python.org/3.6/library/pickle.html

```
The following types can be pickled:

* None, True, and False
* integers, floating point numbers, complex numbers
* strings, bytes, bytearrays
* tuples, lists, sets, and dictionaries containing only picklable objects
* functions defined at the top level of a module (using def, not lambda)
* built-in functions defined at the top level of a module
* classes that are defined at the top level of a module
* instances of such classes whose __dict__ or the result of calling __getstate__() is picklable (see section Pickling Class Instances for details).
```

Thus lambda is not pickable.



Discussion:
I failed to reproduce. No error was raised from the code below.

Environment:
chainer==5.0.0
cupy-cuda92==5.0.0.

```py36.py
Python 3.6.6 |Anaconda, Inc.| (default, Oct  9 2018, 12:34:16)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import multiprocessing
>>> p = multiprocessing.Process(target=lambda *x: x, args=())
>>> p.start()
>>>
```
```py37.py
Python 3.7.0 (default, Jun 28 2018, 13:15:42)
[GCC 7.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import multiprocessing
>>> p = multiprocessing.Process(target=lambda *x: x, args=())
>>> p.start()
>>>
```
I can not reproduce with just :

>>> import multiprocessing
>>> p = multiprocessing.Process(target=lambda *x: x, args=())
>>> p.start()
>>>

But I have to say I also have the same problem, please run the training script if you want to reproduce the error. And hope someone could found a solution



reproduceed with this code:
```
>>> import multiprocessing
>>> multiprocessing.set_start_method('forkserver')
>>> p = multiprocessing.Process(target=lambda *x: x, args=())
>>> p.start()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/aca10310kd/anaconda3/envs/kfac/lib/python3.6/multiprocessing/process.py", line 105, in start
    self._popen = self._Popen(self)
  File "/home/aca10310kd/anaconda3/envs/kfac/lib/python3.6/multiprocessing/context.py", line 223, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "/home/aca10310kd/anaconda3/envs/kfac/lib/python3.6/multiprocessing/context.py", line 291, in _Popen
    return Popen(process_obj)
  File "/home/aca10310kd/anaconda3/envs/kfac/lib/python3.6/multiprocessing/popen_forkserver.py", line 35, in __init__
    super().__init__(process_obj)
  File "/home/aca10310kd/anaconda3/envs/kfac/lib/python3.6/multiprocessing/popen_fork.py", line 20, in __init__
    self._launch(process_obj)
  File "/home/aca10310kd/anaconda3/envs/kfac/lib/python3.6/multiprocessing/popen_forkserver.py", line 47, in _launch
    reduction.dump(process_obj, buf)
  File "/home/aca10310kd/anaconda3/envs/kfac/lib/python3.6/multiprocessing/reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
_pickle.PicklingError: Can't pickle <function <lambda> at 0x7f362ff8ce18>: attribute lookup <lambda> on __main__ failed
>>> 
```
Thanks for the info.  :+1: (and sorry for the delay of our reaction and response)

Resolving patch:
diff --git a/examples/chainermn/imagenet/train_imagenet.py b/examples/chainermn/imagenet/train_imagenet.py
--- a/examples/chainermn/imagenet/train_imagenet.py
+++ b/examples/chainermn/imagenet/train_imagenet.py
@@ -143,7 +143,7 @@ def main():
     # https://chainermn.readthedocs.io/en/stable/tutorial/tips_faqs.html#using-multiprocessiterator
     # This must be done *before* ``chainermn.create_communicator``!!!
     multiprocessing.set_start_method('forkserver')
-    p = multiprocessing.Process(target=lambda *x: x, args=())
+    p = multiprocessing.Process()
     p.start()
     p.join()
 


Test patch: