Skip to content

Commit

Permalink
提升线程池的兼容性
Browse files Browse the repository at this point in the history
  • Loading branch information
yanchunhuo committed Nov 7, 2022
1 parent ad10b8a commit a03f930
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* Js2Py:用于执行js代码,https://github.com/PiotrDabkowski/Js2Py
* sqlacodegen:用于根据数据库表结构生成python对象,https://github.com/agronholm/sqlacodegen
* SQLAlchemy:SQL工具包及对象关系映射(ORM)工具,https://github.com/sqlalchemy/sqlalchemy
* 当前仅支持python3.6.8
* 当前仅支持Python>=3.6
* 项目如需执行java代码(即使用jpype1),则项目目录所在的路径不可包含中文

# [使用]()
Expand Down
42 changes: 29 additions & 13 deletions common/custom_multiprocessing.py
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)

0 comments on commit a03f930

Please sign in to comment.