Python shell getting restarted

前提是你 提交于 2019-12-11 14:09:51

问题


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) 

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

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

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

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


回答1:


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.

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.

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.

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.

"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?



来源:https://stackoverflow.com/questions/48479010/python-shell-getting-restarted

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!