Here is a sample python script.
import sys
print("Hello, world!")
for i, line in enumerate(sys.stdin):
print(line)
print(f"Before breakpoint: {i}")
breakpoint()
print(f"After breakpoint: {i}")
Running seq 1 10 | python tmp.py
launches debugger at the specified breakpoint, however, it automatically reads all the stdin.
seq 1 10 | python tmp.py
Hello, world!
1
Before breakpoint: 0
> .../tmp.py(9)<module>()
-> print(f"After breakpoint: {i}")
(Pdb) 2
(Pdb) 3
(Pdb) 4
(Pdb) 5
(Pdb) 6
(Pdb) 7
(Pdb) 8
(Pdb) 9
(Pdb) 10
(Pdb)
Traceback (most recent call last):
File ".../tmp.py", line 9, in <module>
print(f"After breakpoint: {i}")
File ".../tmp.py", line 9, in <module>
print(f"After breakpoint: {i}")
File ".../python3.10/bdb.py", line 90, in trace_dispatch
return self.dispatch_line(frame)
File ".../python3.10/bdb.py", line 115, in dispatch_line
if self.quitting: raise BdbQuit
bdb.BdbQuit
How to stop breakpoint()
from reading STDIN? i.e., I still want breakpoint()
but just don't want it to automatically consume and execute STDIN.
I looked into the docs[1] and it doesn't mention about this STDIN behavior, nor an option to disable it.
[1] https://docs.python.org/3.10/library/functions.html?highlight=breakpoint#breakpoint. I am using Python 3.10.9 on Ubuntu 20.04.6 LTS (WSL)