使用print()过多会导致失败吗?

dat*_*tta 6 python windows console

TL; DR:

print()结果不会在Windows控制台更新.在IDLE中执行罚款.即使Windows控制台未更新,程序仍在执行.

背景

我有一个文件,test.py其中包含:

编辑:包括我用来查看控制台是否正在更新的条件.最终,一系列X值永远不会再在Console中打印,并且控制台永远不会向上滚动(正如通常在底部生成输出时那样).

count = 0
while True:
    print ("True")
    count += 1
    if count == 10:
            print ("XXXXXXXXX")
            count = 0
Run Code Online (Sandbox Code Playgroud)

当我在cmd.exe其中运行它显然打印了非常大量的True.

但是,运行大约25秒后,它会停止打印,尽管程序仍在运行,可以在任务管理器中看到.

我有一个带有一些进度指标的程序,最终保持在50%,即使它们超过50%只是因为print()没有在控制台输出中显示.

编辑:真正的用例问题.

上面的代码只是一个测试文件,用于查看Console中的打印是否在所有程序中停止,而不是我正在运行的程序.在实践中,我的程序打印到控制台,看起来像:

line [10] >> Progress 05%
Run Code Online (Sandbox Code Playgroud)

哪里line [10]不是真的,但我只是在这里输入,以显示print()在控制台窗口中发送到该行.随着我的程序继续增加:

line [10] >> Progress 06%
line [10] >> Progress 11%
.
.
.
line [10] >> Progress 50%
Run Code Online (Sandbox Code Playgroud)

每次都line [10]被覆盖.我使用ANSI转义字符并相应colorama地移动Console游标:

print('\x1b[1000D\x1b[1A')

这会将光标向左移动1000列,向上移动1行(因此前一行的开始).

print("Progress " + prog + "%")在Console中不再出现的情况正在发生,因为最终下一部分Python会被执行:

line [11] >> Program Complete...

我验证了放入文件夹的结果.因此,当控制台没有更新时,程序继续运行.

编辑:这是运行更新的脚本stdout.

def check_queue(q, dates, dct):
    out = 0
    height = 0

    # print the initial columns and rows of output
    # each cell has a unique id 
    # so they are stored in a dictionary
    # then I convert to list to print by subscripting
    for x in range(0, len(list(dct.values())), 3):
        print("\t\t".join(list(dct.values())[x:x+3]))
        height +=1 # to determine where the top is for cursor

    while True:
        if out != (len(dates) * 2):
            try:
                status = q.get_nowait()
                dct[status[1]] = status[2]
                print('\x1b[1000D\x1b[' + str(height + 1) + 'A')

                # since there was a message that means a value was updated
                for x in range(0, len(list(dct.values())), 3):
                    print("\t\t".join(list(dct.values())[x:x+3]))

                if status[0] == 'S' or 'C' or 'F':
                    out += 1
            except queue.Empty:
                pass
    else:
        break
Run Code Online (Sandbox Code Playgroud)

简而言之,我从一个线程传递消息到队列.然后我更新一个包含唯一单元ID的字典.我更新了值,将控制台中的光标移动到打印列表的左上角位置,并在其上打印.

题:

使用标准输出时,在一段时间内打印到它的次数是否有限制?