简体   繁体   English

在Python中,为什么控制台输出有时会暂停,直到按ctrl-c为止,我该如何停止呢?

[英]In Python, why does console output occasionally pause until ctrl-c is pressed, and how can I stop this?

This issue seems to crop up once every week or so while doing Python development. 在进行Python开发时,这个问题似乎每周大约出现一次。 Whether in Bash on Linux or cmd.exe or Powershell, Python scripts will sometimes pause their output, leading one to believe they may have locked up. 无论是在Linux上的Bash还是cmd.exe或Powershell中,Python脚本有时都会暂停其输出,使人们相信它们可能已被锁定。 Upon having ctrl-c pressed, the console output will resume, and it will be apparent that the script has been executing in the background. 按下ctrl-c后,控制台输出将恢复,并且很明显该脚本已在后台执行。 As if scroll lock had been pressed or something. 好像按下了滚动锁定一样。

The program doesn't matter and it can only be reproduced over time. 该程序无关紧要,只能随时间复制。 You could run the following snip: 您可以运行以下代码段:

import time

i = 0
while True:
    print i
    i++
    time.sleep(1)

And in the next week or so, the console will pause, even though i is still increasing every second in the background. 在接下来的一周左右的时间里,即使我在后台仍然每秒都在增加,控制台也会暂停。

This isn't just poor design on my end - I had this happen to a Celery process more than once & a Django test server, along with my own programs. 这不仅是我的拙劣设计-我在Celery进程,Django测试服务器以及我自己的程序中多次发生了这种情况。 Normally I would just consider it a 'nuisance' but ctrl-c can also accidentally terminate the program if it's actually, really busy. 通常,我只是将其视为“令人讨厌的东西”,但如果ctrl-c实际上非常繁忙,它也可能会意外终止该程序。

This behavior has also existed for my co-workers, but nobody seems to know what to do about it. 我的同事也存在这种行为,但是似乎没有人知道该怎么做。

Does anyone have a solution for this? 有人对此有解决方案吗?

Thanks! 谢谢!

可能是您按下了窗口外或按下了ctrl-S(这会暂停consle输出)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM