在诅咒模式下,stdout 和 stderr 在哪里?
当 curses 处于活动状态时,stdout 和 stderr 会去哪里?
Where do stdout and stderr go when curses is active?
import curses, sys
def test_streams():
print "stdout"
print >>sys.stderr, "stderr"
def curses_mode(stdscr):
test_streams()
test_streams()
curses.wrapper(curses_mode)
实际输出为
stdout
stderr
更新0
预期输出是
stdout
stderr
stdout
stderr
进入,然后退出curses模式,终端中显示的最终文本不变.
entering, and then exiting curses mode with no change to the final text shown in the terminal.
激活curses保存终端文本屏幕的当前内容并清除该屏幕;退出curses 会恢复屏幕的内容(丢弃在curses 统治期间放在屏幕上的任何内容).尝试使用您的代码的这种变体,您会更好地了解正在发生的事情:
Activating curses saves the terminal text screen's current contents and clears said screen; exiting curses restores the screen's contents (tossing away whatever's been put on screen during the reign of curses itself). Try with this variant of your code and you'll see better what's happening:
import curses, sys, time
def test_streams(wot):
print wot, "stdout"
print >>sys.stderr, wot, "stderr"
def curses_mode(stdscr):
test_streams("wrap")
time.sleep(1.0)
test_streams("before")
curses.wrapper(curses_mode)
test_streams("after")
你会注意到屏幕上的 wrap stderr
一秒钟(在睡眠期间)——它覆盖了标准输出部分——然后它消失了,你会看到前后四行现在处于静止状态的屏幕(如果您愿意,您可以添加其他睡眠以了解正在发生的更多细节).
You'll note the wrap stderr
on the screen for a second (during the sleep) -- it's overwritten the stdout part -- then it disappears and you see the four before and after lines on the now-quiescent screen (you can add other sleeps to follow what's happening in even more details, if you care).