V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
jibabi
V2EX  ›  Python

求助 Python multiprocessing 守护进程为什么不允许有子进程?

  •  
  •   jibabi · 2019-06-20 17:02:34 +08:00 · 4291 次点击
    这是一个创建于 1978 天前的主题,其中的信息可能已经有所发展或是发生改变。
    本人代码如下:

    import multiprocessing
    import time

    def process_a():
    for _ in range(10):
    print("process a")
    time.sleep(1)

    def process_b():
    print("process b")
    ps = []
    for _ in range(3):
    p = multiprocessing.Process(target=process_a)
    p.daemon = True
    p.start()
    ps.append(p)
    for i in ps:
    i.join()

    if __name__ == '__main__':
    p = multiprocessing.Process(target=process_b)
    p.daemon = True
    p.start()
    p.join()

    运行报错:AssertionError: daemonic processes are not allowed to have children
    想问一下 multiprocessing 是出于什么原因,决定守护进程不能再创建子进程?谢谢
    2 条回复    2019-07-18 17:36:59 +08:00
    liuguichao
        1
    liuguichao  
       2019-07-03 09:42:03 +08:00
    Note that a daemonic process is not allowed to create child processes. Otherwise a daemonic process would leave its children orphaned if it gets terminated when its parent process exits. Additionally, these are not Unix daemons or services, they are normal processes that will be terminated (and not joined) if non-daemonic processes have exited.
    wuwukai007
        2
    wuwukai007  
       2019-07-18 17:36:59 +08:00
    设置环境变量 export PYTHONOPTIMIZE=1

    ldconfig
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5296 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 09:39 · PVG 17:39 · LAX 01:39 · JFK 04:39
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.