推荐学习书目
› 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
gamexg
V2EX  ›  Python

python 子线程 sys.exit 无法结束进程 ... 除了 os._exit 还有什么办法优雅的结束进程吗?

  •  
  •   gamexg · Sep 10, 2015 · 4296 views
    This topic created in 4033 days ago, the information mentioned may be changed or developed.

    需求是: python 主进程做一些工作,另起一个子线程做一些监控,发现系统异常时终止整个进程的工作,并设置进程退出代码。

    结果发现子线程调用 sys.exit 居然不会终止进程,虽然文档上面写 sys.exit 只是引发异常,但 threading.Thread 把 SystemExit 捕获并忽略了太奇怪了吧?

    os._exit 不执行各种清理操作,除了 os._exit 还有其他优雅的终止进程的办法吗?

    1 replies  •  2015-09-10 19:44:20 +08:00
    ryd994
        1
    ryd994  
       Sep 10, 2015 via Android   ❤️ 1
    子线程退出了啊,主线程没退出啊
    你这样:开线程的时候指定 deamon_thread=True
    想退出的时候调用 exit_main
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2618 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 14:57 · PVG 22:57 · LAX 07:57 · JFK 10:57
    ♥ Do have faith in what you're doing.