Is too much use of print () causing it to fail?

TL DR:

The result is print()not updated in the Windows console. Performs a fine in IDLE. The program runs even if the Windows console is not updated.

Background

I have a file test.pythat contains:

Edit: Included are the conditions that I used to verify that the Console is being updated. In the end, a series of values Xnever prints again in the Console, and the Console never scrolls the backup (as is usually the case when exiting to the bottom).

count = 0
while True:
    print ("True")
    count += 1
    if count == 10:
            print ("XXXXXXXXX")
            count = 0

When I run this in cmd.exe, it obviously prints a very large number True.

However, after about 25 seconds of operation, it stops printing more, although the program is still working and can be seen in the task manager.

, 50%, 50%, , print() .

: .

, , ​​ , , . :

line [10] >> Progress 05%

line [10] , , , print() . :

line [10] >> Progress 06%
line [10] >> Progress 11%
.
.
.
line [10] >> Progress 50%

line [10] . escape- ANSI colorama :

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

1000 1 ( ).

- , print("Progress " + prog + "%") , Python:

line [11] >> Program Complete...

, . , , .

: script 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

, . , . , .

:

stdout , ?

+6
3

(, , ).

, print. -, , , :

import itertools
for i in itertools.count():
    print(i, "True")
+4

Windows 10 64- Python 3.6.2 colorama 0.3.9. , :

import colorama
colorama.init()

def test(M=10, N=1000):
    for x in range(M):
        print('spam')
    for n in range(N):
        print('\x1b[1000D\x1b[' + str(M + 1) + 'A')
        for m in range(M):
            print('spam', m, n)

. N (1000) :

>>> test()
spam 0 999
spam 1 999
spam 2 999
spam 3 999
spam 4 999
spam 5 999
spam 6 999
spam 7 999
spam 8 999
spam 9 999

, Windows, Python colorama, .

+2

, , Python? "", ( ), :

Python

How many times you can print over a period of time is almost exclusively based on the speed that the system executes the code. You could run some test tests (runtime / number of executions) on several platforms to test performance with specific system specifications, but I would say that the probable cause of your problem is related to the system / environment.

+1
source

All Articles