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

请教 multiprocessing 问题,在 window7 下运行可以正常打印, ubuntu 运行一会就卡死了。

  •  
  •   naldo0193 · 2020-08-21 22:13:58 +08:00 · 1458 次点击
    这是一个创建于 1336 天前的主题,其中的信息可能已经有所发展或是发生改变。
    在 window7 下运行可以正常打印,ubuntu 运行一会就卡死了。


    import time,os

    from multiprocessing import Manager,Pool



    def test_try(multiprocess_queue):
    print(os.getpid())
    check_multiprocess_queue = multiprocess_queue.empty()
    if check_multiprocess_queue:
    print('队列为空')
    else:
    each_data = multiprocess_queue.get()

    print(os.getpid())


    if __name__ == '__main__':
    while True:
    multiprocess_queue = Manager().Queue()
    multiprocess_queue.put('a')
    pool = Pool(processes=2) # 最大核数
    # 异步进程
    for d in range(2):
    pool.apply_async(func=test_try, args=(multiprocess_queue,))

    pool.close()
    pool.join()
    第 1 条附言  ·  2020-08-22 15:11:06 +08:00

    import time,os from multiprocessing import Manager,Pool

    def test_try(multiprocess_queue):

    print(os.getpid())
    
    check_multiprocess_queue = multiprocess_queue.empty()
    
    if check_multiprocess_queue:
        print('队列为空')
    else:
        each_data = multiprocess_queue.get()
        print(os.getpid())
    

    if name == 'main':

    while True:
    
        multiprocess_queue = Manager().Queue()
        multiprocess_queue.put('a')
    
        pool = Pool(processes=2) # 最大核数
       
        for d in range(2):
            pool.apply_async(func=test_try, args=(multiprocess_queue,))
    
        pool.close()
        pool.join()
    
    3 条回复    2020-08-21 22:52:32 +08:00
    AlohaV2
        1
    AlohaV2  
       2020-08-21 22:27:21 +08:00 via iPhone
    没有对齐对于 python 代码来说是很致命的,比如我不知道 while True 的作用范围是什么
    dingwen07
        2
    dingwen07  
       2020-08-21 22:47:57 +08:00 via iPhone
    你这没缩进让人怎么看
    lzp729
        3
    lzp729  
       2020-08-21 22:52:32 +08:00
    linux 默认是 fork
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3614 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 04:34 · PVG 12:34 · LAX 21:34 · JFK 00:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.