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

2024-05-20 15:27:18 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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>")

Tags: 字符串代码text用户from文本import程序