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

标签 python multithreading

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

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 .

关于python - 使用python多线程不断获取输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9486136/

相关文章:

python - Web.py - 属性错误 : 'module' object has no attribute 'application'

Python/sqlite : get column values as a list/tuple from rows where other columns have certain values

python - pyinstaller 无法使用 tkinter

c - 程序的编译在执行前是否会在缓存中存储一​​些数据?? (C, Linux)

Python 限制多线程

python - 在 Windows 中检测文件名的大小写不匹配(最好使用 python)?

python - 在 tkinter 中交互式验证条目小部件内容

python - 调用嵌入式Python模块时,是否切换了线程?

multithreading - 在线程上运行进程 (JSF 2.2 - WELD 2.3)

c++ - 线程安全的 TBB::concurrent_hash_map 删除