TypeError: cannot pickle '_io.TextIOWrapper' object
fordguo opened this issue · 1 comments
my env:mac os ,python3.8.5,django 3.1
exception:
File "/Users/ford/workspace/products/ve/.venv/lib/python3.8/site-packages/django/core/management/base.py", line 371, in execute output = self.handle(*args, **options) File "/Users/ford/workspace/products/ve/.venv/lib/python3.8/site-packages/chroniker/management/commands/cron.py", line 342, in handle run_cron( File "/Users/ford/workspace/products/ve/.venv/lib/python3.8/site-packages/chroniker/management/commands/cron.py", line 214, in run_cron proc.start() File "/Users/ford/workspace/products/ve/.venv/lib/python3.8/site-packages/chroniker/utils.py", line 426, in start super(TimedProcess, self).start(*args, **kwargs) File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/process.py", line 121, in start self._popen = self._Popen(self) File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/context.py", line 224, in _Popen return _default_context.get_context().Process._Popen(process_obj) File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/context.py", line 284, in _Popen return Popen(process_obj) File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/popen_spawn_posix.py", line 32, in __init__ super().__init__(process_obj) File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/popen_fork.py", line 19, in __init__ self._launch(process_obj) File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/popen_spawn_posix.py", line 47, in _launch reduction.dump(process_obj, fp) File "/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/python3.8/multiprocessing/reduction.py", line 60, in dump ForkingPickler(file, protocol).dump(obj) TypeError: cannot pickle '_io.TextIOWrapper' object
According to https://docs.python.org/3.8/library/multiprocessing.html#contexts-and-start-methods:
Changed in version 3.8: On macOS, the spawn start method is now the default. The fork start method should be considered unsafe as it can lead to crashes of the subprocess.
To continue using the fork method anyways to avoid the error above, I added the following lines to myproject/__init__.py
:
import multiprocessing
import sys
if sys.version_info[:2] == (3, 8) and sys.platform == 'darwin':
multiprocessing.set_start_method('fork')