HI All:
这边初学习Tornado框架,写了以下代码:
g_ConnectionCount = 0
class MyTcpServer(TCPServer):
def handle_stream(self, stream, address):
print "New Connection"
g_ConnectionCount = g_ConnectionCount + 1
print "g_ConnectionCount",g_ConnectionCount
pass
pass
if __name__ == "__main__":
_myServer = MyTcpServer()
_myServer.listen(6666)
_ioLoop = IOLoop.instance()
tornado.autoreload.start(_ioLoop)
_ioLoop.start()
pass
本以为httpServer下是不行的,TcpServer下应该可行才对。但实际运行结果:UnboundLocalError: local variable 'g_ConnectionCount' referenced before assignment
Tornado 不是单进程单线程么?python下声明一个全局的g_ConnectionCount应该能被访问到才是。
这边初学习Tornado框架,写了以下代码:
g_ConnectionCount = 0
class MyTcpServer(TCPServer):
def handle_stream(self, stream, address):
print "New Connection"
g_ConnectionCount = g_ConnectionCount + 1
print "g_ConnectionCount",g_ConnectionCount
pass
pass
if __name__ == "__main__":
_myServer = MyTcpServer()
_myServer.listen(6666)
_ioLoop = IOLoop.instance()
tornado.autoreload.start(_ioLoop)
_ioLoop.start()
pass
本以为httpServer下是不行的,TcpServer下应该可行才对。但实际运行结果:UnboundLocalError: local variable 'g_ConnectionCount' referenced before assignment
Tornado 不是单进程单线程么?python下声明一个全局的g_ConnectionCount应该能被访问到才是。