V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
sure15
V2EX  ›  Python

为什么 python 官方的这个代码在我的电脑上无法执行?

  •  
  •   sure15 · Mar 31, 2015 · 3783 views
    This topic created in 4046 days ago, the information mentioned may be changed or developed.
    首先说下环境:win7 64位+IDLE+python3.4.3
    这个代码无法运行:
    from multiprocessing import Process

    def f(name):
    print('hello', name)

    if __name__ == '__main__':
    p = Process(target=f, args=('bob',))
    p.start()
    p.join()

    代码来源(https://docs.python.org/3/library/multiprocessing.html)
    Supplement 1  ·  Mar 31, 2015
    ---------------更新------------------
    不知道为什么,发现在cmd下可以智能,但是在IDLE里按F5调试的时候无法执行。
    IDLE调试的情况下结果:
    >>> ================================ RESTART ================================
    >>>
    >>>
    Supplement 2  ·  Mar 31, 2015
    是执行不是智能,错别字。
    9 replies    2015-03-31 19:01:46 +08:00
    lerry
        1
    lerry  
       Mar 31, 2015
    错误提示是什么,无法执行的表现是什么?
    wuhang89
        2
    wuhang89  
       Mar 31, 2015
    你既然是学python起码要知道最基本的代码格式吧

    from multiprocessing import Process

    def f(name):
    print('hello', name)

    p = Process(target=f, args=('bob',))
    p.start()
    p.join()
    wuhang89
        3
    wuhang89  
       Mar 31, 2015
    from multiprocessing import Process

    def f(name):
    print('hello', name)

    p = Process(target=f, args=('bob',))
    p.start()
    p.join()
    wuhang89
        4
    wuhang89  
       Mar 31, 2015
    sorry,这个回复框无法贴代码格式,代码是可以执行的,已测。
    jun4rui
        5
    jun4rui  
       Mar 31, 2015
    可执行,已经测试。平台是Linux Mint 1.7.1+Python 3.4.0
    >
    from multiprocessing import Process

    def f(name):
    print('hello', name)

    if __name__ == '__main__':
    p = Process(target=f, args=('bob',))
    p.start()
    p.join()
    sure15
        6
    sure15  
    OP
       Mar 31, 2015
    @lerry 无任何提示,就是这样子:
    >>> ================================ RESTART ================================
    >>>
    >>>
    sure15
        7
    sure15  
    OP
       Mar 31, 2015
    @wuhang89 >>> ================================ RESTART ================================
    >>>
    >>>
    我的是这种提示,不知道你用的是什么环境?
    aaaa007cn
        8
    aaaa007cn  
       Mar 31, 2015
    又没有重定向子进程的输出
    当然没提示啊
    sandtears
        9
    sandtears  
       Mar 31, 2015
    IDLE 只能获取到你父进程的输出,然而你的输出是在子进程的。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4953 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 55ms · UTC 09:51 · PVG 17:51 · LAX 02:51 · JFK 05:51
    ♥ Do have faith in what you're doing.