Repository: pytorch
Issue: TypeError: can't pickle _thread.lock objects when using spawn / forkserver
Labels: module: pickle,triaged,better-engineering

## 🐛 Bug

When using spawn or forkserver with DataLoader, you get this error:

```
TypeError: can't pickle _thread.lock objects
```
Full traceback:
```
 File "/data/users/gibiansky/fbsource/fbcode/buck-out/dev/gen/langtech/tts/experimental/modeling/main#link-tree/torch/utils/data/dataloader.py", line 355, in __iter__
    return self._get_iterator()
  File "/data/users/gibiansky/fbsource/fbcode/buck-out/dev/gen/langtech/tts/experimental/modeling/main#link-tree/torch/utils/data/dataloader.py", line 301, in _get_iterator
    return _MultiProcessingDataLoaderIter(self)
  File "/data/users/gibiansky/fbsource/fbcode/buck-out/dev/gen/langtech/tts/experimental/modeling/main#link-tree/torch/utils/data/dataloader.py", line 301, in _get_iterator
    return _MultiProcessingDataLoaderIter(self)
  File "/data/users/gibiansky/fbsource/fbcode/buck-out/dev/gen/langtech/tts/experimental/modeling/main#link-tree/torch/utils/data/dataloader.py", line 914, in __init__
    w.start()
  File "/data/users/gibiansky/fbsource/fbcode/buck-out/dev/gen/langtech/tts/experimental/modeling/main#link-tree/torch/utils/data/dataloader.py", line 914, in __init__
    w.start()
  File "/usr/local/fbcode/platform007/lib/python3.7/multiprocessing/process.py", line 112, in start
    self._popen = self._Popen(self)
  File "/usr/local/fbcode/platform007/lib/python3.7/multiprocessing/process.py", line 112, in start
    self._popen = self._Popen(self)
  File "/usr/local/fbcode/platform007/lib/python3.7/multiprocessing/context.py", line 223, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "/usr/local/fbcode/platform007/lib/python3.7/multiprocessing/context.py", line 223, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "/usr/local/fbcode/platform007/lib/python3.7/multiprocessing/context.py", line 284, in _Popen
    return Popen(process_obj)
  File "/usr/local/fbcode/platform007/lib/python3.7/multiprocessing/context.py", line 284, in _Popen
    return Popen(process_obj)
  File "/usr/local/fbcode/platform007/lib/python3.7/multiprocessing/popen_spawn_posix.py", line 32, in __init__
    super().__init__(process_obj)
  File "/usr/local/fbcode/platform007/lib/python3.7/multiprocessing/popen_spawn_posix.py", line 32, in __init__
    super().__init__(process_obj)
  File "/usr/local/fbcode/platform007/lib/python3.7/multiprocessing/popen_fork.py", line 20, in __init__
    self._launch(process_obj)
  File "/usr/local/fbcode/platform007/lib/python3.7/multiprocessing/popen_fork.py", line 20, in __init__
    self._launch(process_obj)
  File "/usr/local/fbcode/platform007/lib/python3.7/multiprocessing/popen_spawn_posix.py", line 47, in _launch
    reduction.dump(process_obj, fp)
  File "/usr/local/fbcode/platform007/lib/python3.7/multiprocessing/popen_spawn_posix.py", line 47, in _launch
    reduction.dump(process_obj, fp)
  File "/usr/local/fbcode/platform007/lib/python3.7/multiprocessing/reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
  File "/usr/local/fbcode/platform007/lib/python3.7/multiprocessing/reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)
```

## Expected behavior

According to this issue comment this is due to the start method, and it doesn't happen when using just fork: 

https://github.com/Koed00/django-q/issues/424#issuecomment-708642064

While perhaps there may be other fixes, for now it would be incredibly useful if the error message indicated that the issue was that the arguments are not pickleable but need to be. This could be achieved by trying to pickle the arguments before `w.start()` or catching the error and adding info to the traceback.

## Environment

fbcode?