我写了这个最低限度的代码来解释我的情况:
import threading
import time
import eventlet
eventlet.monkey_patch()
def printing_function():
while True:
# here i want to do some work
print "printing"
time.sleep(1)
if __name__ == '__main__':
thread = threading.Thread(target=printing_function)
thread.start()
while True:
# here i want to wait for users input
raw_input("raw input\n")
print "inside main loop"
time.sleep(1)
即使我有 2 个线程,当我调用 raw_input 时它们都被阻塞了。当我注释掉 eventlet.monkey_patch() 时,只有一个线程被阻塞,另一个线程继续打印“打印”。为什么以及我应该怎么做?