Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: cannot pickle '_io.TextIOWrapper' object #208

Open
fordguo opened this issue Sep 1, 2020 · 1 comment
Open

TypeError: cannot pickle '_io.TextIOWrapper' object #208

fordguo opened this issue Sep 1, 2020 · 1 comment

Comments

@fordguo
Copy link

fordguo commented Sep 1, 2020

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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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/[email protected]/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

@cchurch
Copy link

cchurch commented Nov 12, 2020

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')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants