- 论坛徽章:
- 9
|
#!/bin/env python
# -*- coding: UTF-8 -*-
from ws4py.client.threadedclient import WebSocketClient
import MySQLdb,re,os,sys
class DummyClient(WebSocketClient):
#ws连接建立后,会自动执行opened函数
def opened(self):
#连接成功后打印200
print 200
os._exit(0)
#ws连接挂起后,会自动执行closed函数
def closed(self, code, reason=None):
print "Closed down", code, reason
def received_message(self, m):
print m
def check_status():
try:
url = 'ws://echo.websocket.org'
ws = DummyClient(url)
ws.connect()
ws.run_forever()
except Exception,e:
#print e
revalue = re.findall('200 OK',str(e))
#返回500表示建立ws连接出现问题
if revalue :
print 500,e
#返回400表示有其他错误
else :
print 400 ,e
except KeyboardInterrupt:
ws.close()
if __name__ == "__main__":
check_status()
以上代码是python2.7环境下的
执行python scripts.py 标准输出会得到200
执行python scripts.py >> log 2>&1 查看log 未收集到任何日志,标准输出也没有打印任何东西
那标准输出哪里去了,求解
|
|