Skip to main content
 首页 » 编程设计

python之使用python多线程不断获取输入

2025年05月04日21zhengyun_ustc

我想编写一个程序,它每秒打印一个字符串,另一方面它允许用户编写文本,我有下面的代码片段。我的问题是每次打印新行时,输入行也会受到干扰。有没有办法将输出线与输入线分开?

import time 
from thread import start_new_thread 
 
def heron(): 
  while 1: 
  time.sleep(1) 
  print "some text" 
 
start_new_thread(heron,()) 
c = raw_input("Enter text>") 

请您参考如下方法:

如果没有 curses,我怀疑你能否做到这一点.可能还有另一种方式,但我认为它不会很漂亮。有一个基本的操作方法 here .