currently I'm working on my Backend websserver using tornado.
The problem i have right now:
- when a request is made and the server is processing the request all other request are blocked
My RequestHandler:
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 )
My 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
My update_sevice():
process = Popen( [ command ], stdout=PIPE, stderr=PIPE, shell=True )
output, error = process.communicate()
The thing is, that I need the result of the update_all() method.
So is there a possibility to make this request not block my whole server for requests?
Thank you!
update.update_all()a coroutine? Does it use non-blocking I/O to do its work?update_servicelooks like. :) Ultimately, we need to know if you're making a slow, blocking call somewhere insideupdate_all.process = Popen( [ command ], stdout=PIPE, stderr=PIPE, shell=True )to run a generated command. Generally I'm calling 'git pull' commands on severall directoriesPopencommand to finish? Because that will definitely block the event loop.