Python shell 重新启动 [英] Python shell getting restarted

查看:70
本文介绍了Python shell 重新启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Shell 重新启动而不打印输出.

Shell restarts without printing the output.

import tensorflow as tf 
from tensorflow.python.client import timeline 


a = tf.random_normal([2000, 5000]) 
b = tf.random_normal([5000, 1000]) 
res = tf.matmul(a, b) 
print ('aaaaaaaaaaaaaaa')

with tf.Session() as sess:

    # add additional options to trace the session execution 
    options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)

    run_metadata = tf.RunMetadata()

    sess.run(res, options=options, run_metadata=run_metadata) 
    print ('bbbbbbbbb')

    # Create the Timeline object, and write it to a json file 
    fetched_timeline = timeline.Timeline(run_metadata.step_stats) 
    chrome_trace = fetched_timeline.generate_chrome_trace_format() 
    with open('timeline_01.json', 'w') as f: 
        f.write(chrome_trace) 

Python idle 不打印输出但总是打印:

The Python idle doesn't print the output but always prints:

================== RESTART: C:\Users\hirplk\Desktop\test.py ==================
aaaaaaaaaaaaaaa

=============================== RESTART: Shell ===============================

每当我运行任何代码时都会发生这种情况.这有什么具体问题吗?这是在我最近多次安装 tensorflow 之后发生的.

This happens whenever I run any code. Is there a specific issue for this? This happened after I recently installed tensorflow for several times.

推荐答案

我很确定 cpython bugs.python.org 跟踪器上没有关于 IDLE shell 在不应该重新启动时(当调试器不在时)的问题是使用).我也不知道最近有任何关于 SO 的问题.

I am rather sure that there is no issue on the cpython bugs.python.org tracker about the IDLE shell restarting when it should not (when the debugger is not is use). Nor do I know of any recent question about such on SO.

您似乎启动了 IDLE,编辑了 C:\Users\hirplk\Desktop\test.py,然后按 F5 或单击菜单项运行它.正常情况下,IDLE 开始在新的用户代码进程中执行您的代码,与 IDLE 接口进程分开.您的代码打印了 'a's 字符串,它出现在 IDLE 进程的 Shell 窗口中.之后,在 b 字符串打印之前的 tensorflow 调用之一使用户进程崩溃.当 IDLE 进程失去与用户进程的通信时,它会重新启动交互式 Shell.这是故意的.

It appears that you started IDLE, edited C:\Users\hirplk\Desktop\test.py, and ran it by either hitting F5 or clicking the menu entry. As is normal, IDLE started to execute your code in a new user code process, separate from the IDLE interface process. Your code printed the string of 'a's, which appeared in the Shell window in the IDLE process. After that, one of the tensorflow calls before the b-string print crashed the user process. When the IDLE process loses communication with the user process, it restarts the interactive Shell. This is intentional.

如果 IDLE 已安装并正常运行,则查看 RESTART: Shell 行的唯一其他方法是显式选择 Restart Shell菜单.

If IDLE is installed and functioning correctly, the only other way to see the RESTART: Shell line is to explicitly select Restart Shell from the menu.

要确定您的 IDLE 安装是否有问题,请从命令行运行您的代码而不涉及 IDLE.例如,在命令提示符窗口中输入 py C:\Users\hirplk\Desktop\test.py.

To determine whether or not your IDLE installation is the problem, run your code from the command line without involving IDLE. For example, enter py C:\Users\hirplk\Desktop\test.py in a Command Prompt window.

每当我运行任何代码时都会发生这种情况."你的意思是,如果你在编辑器中输入print('Hello')`,保存并运行,你会看到重启行而不做任何事情?如果是这样,你要么有一个需要修复的错误安装,要么可能是一个有问题的安装旧版本的 Python/IDLE 没用过,需要更换.你用的是什么版本的 Python/IDLE?

"This happens whenever I run any code." Do you mean that if you enter "print('Hello')` in the editor, save, and run, you see the restart line without doing anything? If so, you either have a buggy installation that needs to be fixed or possibly an old version of Python/IDLE that I never used that needs to be replaced. What version of Python/IDLE are you using?

这篇关于Python shell 重新启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆