您的位置:首页 > 其它

eventlet.backdoor 的使用

2014-01-02 16:11 316 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/ssdxiao/article/details/17759149

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
n = 0
while True :
if should_printing == True:
print "printing",n
n = n+1
time.sleep(1)

def _dont_use_this():
print("Don't use this, just disconnect instead")

if __name__ == '__main__':

backdoor_locals = {'exit': _dont_use_this,
'quit': _dont_use_this,
'off':turn_off_printing,
}
eventlet.spawn(backdoor.backdoor_server, eventlet.listen(('localhost', 3000)), locals=backdoor_locals)

thread = threading.Thread(target=printing_function)
thread.start()

while(1):
time.sleep(1)

eventlet 提供了一种查看程序运行,debug的方式,称为backdoor  他是在每个程序的后台执行了一个telnet的服务器。这样可以远程登录来查看程序的运行状态。


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: