prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.28k stars 715 forks source link

Output blocks after 65k lines when using run_in_terminal #835

Open jeroen-dhollander opened 5 years ago

jeroen-dhollander commented 5 years ago

Hey all,

When using run_in_terminal, the output will block forever after printing 65536 lines. This is using the latest prompt_toolkit version (2.0.8), and python 3.

To reproduce simply run the this_blocks_after_65k_lines method:

def this_blocks_after_65k_lines():
    i = 0
    while True:
        run_in_terminal(lambda: print_formatted_text(FormattedText([('', f'{i}')])))
        i = i + 1

def this_does_not_block():
    i = 0
    while True:
        print_formatted_text(FormattedText([('', f'{i}')]))
        i = i + 1

The output will keep scrolling numbers until 65536, then it stops.

jonathanslenders commented 5 years ago

That's definitely a bug. I wonder whether we are leaking file descriptors. I have to look into this. Thanks for reporting the issue!

jeroen-dhollander commented 5 years ago

I actually also suspected leaked file descriptors, but I could see no increase when watching /proc/<pid>/fd