【发布时间】:2015-08-15 20:03:46
【问题描述】:
目前我正在使用 tornado 开发我的后端网络服务器。
我现在遇到的问题:
- 当发出请求并且服务器正在处理该请求时,所有其他请求都被阻止
我的请求处理程序:
class UpdateServicesRequestHandler( RequestHandler ):
@gen.coroutine
def get( self ):
update = ServiceUpdate()
response = yield update.update_all( )
if self.request.headers.get('Origin'):
self.set_header( 'Access-Control-Allow-Origin', self.request.headers.get('Origin') )
self.set_header( 'Content-Type', 'application/json')
self.write( response )
我的update_all():
@gen.coroutine
def update_all( self ):
for service in self.port_list:
response = yield self.update_service( str( service.get( 'port' ) ) )
self.response_list.append( response )
self.response = json.dumps( self.response_list )
return self.response
我的update_sevice():
process = Popen( [ command ], stdout=PIPE, stderr=PIPE, shell=True )
output, error = process.communicate()
问题是,我需要update_all() 方法的结果。
那么是否有可能使这个请求不会阻塞我的整个服务器的请求?
谢谢!
【问题讨论】:
-
update.update_all()是协程吗?它是否使用非阻塞 I/O 来完成其工作? -
刚刚更新了我的帖子..
-
现在我们需要知道
update_service的样子。 :) 最终,我们需要知道您是否在update_all内部某处进行了缓慢的阻塞呼叫。 -
我正在使用子进程
process = Popen( [ command ], stdout=PIPE, stderr=PIPE, shell=True )运行生成的命令。通常我在几个目录上调用“git pull”命令 -
你是在等待
Popen命令完成吗?因为那肯定会阻塞事件循环。
标签: python python-3.x asynchronous tornado