我写了这个最小的代码来解释我的情况:
import threading
import time
import eventlet
from eventlet import backdoor
eventlet.monkey_patch()
global should_printing
should_printing = True
def turn_off_printing():
global should_printing
should_printing = not should_printing
def printing_function():
global should_printing
while should_printing == True:
print "printing"
time.sleep(1)
def console():
while True:
print "inside console"
time.sleep(1)
if __name__ == '__main__':
eventlet.spawn(backdoor.backdoor_server, eventlet.listen(('localhost', 3000)))
thread = threading.Thread(target=printing_function)
thread.start()
thread = threading.Thread(target=console)
thread.start()
执行后,我通过 telnet 连接,导入我的模块并调用 turn_off_printing()。但它不起作用。我犯了错误,还是不可能?