Skip to content

Commit

Permalink
fix async launch of notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
molotgor committed Jun 19, 2024
1 parent deb62a3 commit 82a362f
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,9 @@ async def reqArguments(req: Request):
return web.json_response(params)


def launchNotebook(input, arguments=None, file_name=None):
async def launchNotebook(input, arguments=None, file_name=None):
global serverStatus
print('launching notebook {input} with {arguments}'.format(input=input, arguments=arguments))
serverStatus = 'busy'
logOut: str = (logDir + '/%s.log.ipynb' % file_name) if logDir and file_name else None
try:
with pm.utils.chdir(input[:input.rfind('/')]):
Expand All @@ -269,7 +268,6 @@ def launchNotebook(input, arguments=None, file_name=None):
print(error)
return web.HTTPInternalServerError(reason=error)
finally:
serverStatus = 'idle'
print(asyncio.all_tasks())


Expand All @@ -293,8 +291,6 @@ async def reqLaunch(req: Request):
"""
path = req.rel_url.query.get('path')
print('/execute?path={path}'.format(path=str(path)))
if serverStatus != 'idle':
return web.HTTPServiceUnavailable(reason='server is currently busy')
if not req.can_read_body:
return web.HTTPBadRequest(reason='body with parameters not present')
path = req.rel_url.query.get('path')
Expand All @@ -309,7 +305,7 @@ async def reqLaunch(req: Request):
output_path = resultsDir + '/%s.jsonl' % str(file_name)
parameters = await req.json()
parameters['output_path'] = output_path
launchNotebook(pathConverted, parameters, file_name)
asyncio.shield(asyncio.create_task(launchNotebook(pathConverted, parameters, file_name)))
return web.json_response({'path': replacePathLocalToServer(output_path)})


Expand All @@ -333,8 +329,6 @@ async def reqResult(req: Request):
"""
path = req.rel_url.query.get('path')
print('/result?path={path}'.format(path=str(path)))
if serverStatus != 'idle':
return web.HTTPServiceUnavailable(reason='server is currently busy')
pathConverted = path and replacePathServerToLocal(path)
if not path or not os.path.isfile(pathConverted):
return web.HTTPNotFound()
Expand Down

0 comments on commit 82a362f

Please sign in to comment.