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

python 多线程问题求教

  •  
  •   azkb · Feb 22, 2016 · 3714 views
    This topic created in 3868 days ago, the information mentioned may be changed or developed.
    程序用来并发删除文件,是一个 io 密集型的任务,

    中间碰到一个奇怪的现象,程序中用到 logging 模块,因为是线程安全的,并每太在意,

    第二天发现程序卡住了( stdout 重定向的文件,日志文件都没更新), strace 进程以后,程序继续执行,标准输出和日志都开始正常更新,不知道问题是出在线程调度还是哪,求大神指点
    5 replies  •  2016-02-22 19:48:12 +08:00
    boyhailong
        1
    boyhailong  
       Feb 22, 2016
    无码无真相
    ethego
        2
    ethego  
       Feb 22, 2016
    写入同一个文件造成的死锁?
    azkb
        3
    azkb  
    OP
       Feb 22, 2016
    @ethego 还真像死锁,不过 ethego 是指 logging 到同一文件,还是 stdout 重定向导致的死锁呢
    ethego
        4
    ethego  
       Feb 22, 2016
    @azkb 这个你自己最清楚啊,看有没有哪里是有可能多个线程同时挤占一个文件的
    azkb
        5
    azkb  
    OP
       Feb 22, 2016
    文件只有 3 个:
    1. logging 日志文件:只有 logging 调用,线程安全,应该问题不大
    2. stdout :线程中有调用 os.system ,标准输出重定向到文件 stdout
    3. stderr :同上,标准错误

    哦,知道了,可能是 os.system 调用的外部程序的标准输出也和我的程序都定向到了同一个文件,导致 stdout 文件冲突,那应该把外部程序的标准输出重定向 /dev/null 或其他文件就不会冲突了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2855 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 03:24 · PVG 11:24 · LAX 20:24 · JFK 23:24
    ♥ Do have faith in what you're doing.