在stdin
或close
关闭dup2
时,PDB立即退出。
(Pdb) list
1 -> import os
2 import sys
3
4 print open(os.devnull, 'r+b').fileno()
5 print sys.stdin.fileno()
6
7 with open(os.devnull, 'r+b') as nullfile:
8 os.dup2(nullfile.fileno(), sys.stdin.fileno())
9
10 print "hello"
[EOF]
(Pdb) n
> /tmp/fd.py(2)<module>()
-> import sys
(Pdb)
> /tmp/fd.py(4)<module>()
-> print open(os.devnull, 'r+b').fileno()
(Pdb)
3
... omitted ...
-> os.dup2(nullfile.fileno(), sys.stdin.fileno())
(Pdb)
> /tmp/fd.py(10)<module>()
-> print "hello"
(Pdb) <-- exits immediately
root@swift01:/tmp#