-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yanchunhuo
committed
Nov 7, 2022
1 parent
ad10b8a
commit a03f930
Showing
2 changed files
with
30 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,42 @@ | ||
# @Author : yanchunhuo | ||
# @Time : 2020/1/15 16:25 | ||
# | ||
# custom_multiprocessing.py | ||
# @author yanchunhuo | ||
# @description | ||
# @github https://github.com/yanchunhuo | ||
# @created 2022-08-20T17:27:14.632Z+08:00 | ||
# @last-modified 2022-11-07T19:44:59.558Z+08:00 | ||
# | ||
# 参考 https://stackoverflow.com/questions/52948447/error-group-argument-must-be-none-for-now-in-multiprocessing-pool | ||
|
||
from multiprocessing.pool import Pool | ||
import multiprocessing | ||
|
||
class NoDaemonProcess(multiprocessing.Process): | ||
"""重构multiprocessing.Process类,将进程始终定义为非守护进程 | ||
Args: | ||
multiprocessing (_type_): _description_ | ||
Returns: | ||
_type_: _description_ | ||
""" | ||
重构multiprocessing.Process类,将进程始终定义为非守护进程 | ||
""" | ||
def _get_daemon(self): | ||
""" | ||
总返回非守护进程属性值 | ||
""" | ||
@property | ||
def daemon(self): | ||
return False | ||
|
||
def _set_daemon(self, value): | ||
@daemon.setter | ||
def daemon(self, value): | ||
pass | ||
|
||
daemon = property(_get_daemon, _set_daemon) | ||
class NoDaemonContext(type(multiprocessing.get_context())): | ||
Process = NoDaemonProcess | ||
|
||
class Custom_Pool(Pool): | ||
"""重构multiprocessing.Pool类 | ||
Args: | ||
Pool (_type_): _description_ | ||
""" | ||
重构multiprocessing.Pool类 | ||
""" | ||
Process = NoDaemonProcess | ||
def __init__(self, *args, **kwargs): | ||
kwargs['context'] = NoDaemonContext() | ||
super(Custom_Pool, self).__init__(*args, **kwargs) |