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
loriann
V2EX  ›  Python

Python 进程和线程问题,请指教

  •  
  •   loriann · 2020-04-15 17:29:57 +08:00 · 1615 次点击
    这是一个创建于 1443 天前的主题,其中的信息可能已经有所发展或是发生改变。

    假设我创建了 5 个线程,在这 5 个线程中使用了 popen 函数。那这 5 个线程是复制了 5 个父进程的信息吗。新创建的子进程会不会也有 5 个线程?

    Nitroethane
        1
    Nitroethane  
       2020-04-15 18:46:25 +08:00
    Linux 下,在一个多线程的进程中,每个 thread 里 fork 一个 child process 的话每个新的 child process 只有创建此 process 的 thread,即只存在一个 thread
    Reference: https://stackoverflow.com/a/39890957/6628963
    loriann
        2
    loriann  
    OP
       2020-04-15 21:57:48 +08:00
    谢谢,我刚才我试验了一下,确实 fork 的进程只有一个线程
    frostming
        3
    frostming  
       2020-04-16 12:07:46 +08:00
    popen 并不是 fork 出来的而是 spawn 出来的,进程信息跟父进程不共享
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3330 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 13:29 · PVG 21:29 · LAX 06:29 · JFK 09:29
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.