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

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

  •  
  •   sure15 · 2015-03-31 16:38:24 +08:00 · 2969 次点击
    这是一个创建于 3285 天前的主题,其中的信息可能已经有所发展或是发生改变。
    首先说下环境: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)
    第 1 条附言  ·  2015-03-31 17:17:30 +08:00
    ---------------更新------------------
    不知道为什么,发现在cmd下可以智能,但是在IDLE里按F5调试的时候无法执行。
    IDLE调试的情况下结果:
    >>> ================================ RESTART ================================
    >>>
    >>>
    第 2 条附言  ·  2015-03-31 17:19:06 +08:00
    是执行不是智能,错别字。
    9 条回复    2015-03-31 19:01:46 +08:00
    lerry
        1
    lerry  
       2015-03-31 16:47:30 +08:00
    错误提示是什么,无法执行的表现是什么?
    wuhang89
        2
    wuhang89  
       2015-03-31 16:48:36 +08:00
    你既然是学python起码要知道最基本的代码格式吧

    from multiprocessing import Process

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

    p = Process(target=f, args=('bob',))
    p.start()
    p.join()
    wuhang89
        3
    wuhang89  
       2015-03-31 16:48:56 +08:00
    from multiprocessing import Process

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

    p = Process(target=f, args=('bob',))
    p.start()
    p.join()
    wuhang89
        4
    wuhang89  
       2015-03-31 16:49:28 +08:00
    sorry,这个回复框无法贴代码格式,代码是可以执行的,已测。
    jun4rui
        5
    jun4rui  
       2015-03-31 17:00:54 +08:00
    可执行,已经测试。平台是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
       2015-03-31 17:05:59 +08:00
    @lerry 无任何提示,就是这样子:
    >>> ================================ RESTART ================================
    >>>
    >>>
    sure15
        7
    sure15  
    OP
       2015-03-31 17:06:54 +08:00
    @wuhang89 >>> ================================ RESTART ================================
    >>>
    >>>
    我的是这种提示,不知道你用的是什么环境?
    aaaa007cn
        8
    aaaa007cn  
       2015-03-31 17:13:11 +08:00
    又没有重定向子进程的输出
    当然没提示啊
    sandtears
        9
    sandtears  
       2015-03-31 19:01:46 +08:00
    IDLE 只能获取到你父进程的输出,然而你的输出是在子进程的。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5159 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 01:17 · PVG 09:17 · LAX 18:17 · JFK 21:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.