|
@@ -74,35 +74,45 @@ class ConnHandlerBeeWatch(digilib.network.ConnHandlerBase):
|
|
|
cmd,*args = data
|
|
|
kwargs = {"args":args,"command":cmd,"respond":self.respond}
|
|
|
func = beewatch._commands.get(cmd,False)
|
|
|
+ task = None
|
|
|
if func == False:
|
|
|
await self.respond("Unknown command")
|
|
|
return
|
|
|
try:
|
|
|
- retval = func(**kwargs)
|
|
|
- if hasattr(retval,"__await__"):
|
|
|
- await curio.spawn(self.wait_for_func,retval)
|
|
|
-
|
|
|
-
|
|
|
+ coro = func(**kwargs)
|
|
|
+ if hasattr(coro,"__await__"):
|
|
|
+ task = await coro
|
|
|
except Exception as e:
|
|
|
- lserver.error("Error while calling api func",exc_info=e)
|
|
|
+ lserver.error("api_func raised an error:",exc_info=e)
|
|
|
tb = traceback.format_exc()
|
|
|
- await self.respond(tb)
|
|
|
-
|
|
|
- async def respond(self,text,*args):
|
|
|
- await self.send(text)
|
|
|
-
|
|
|
- async def wait_for_func(self,coro):
|
|
|
- try:
|
|
|
- task = await curio.spawn(coro)
|
|
|
- try:
|
|
|
- await task.join()
|
|
|
- except Exception as e:
|
|
|
- lserver.error("error during api_func execution",exc_info=e)
|
|
|
-
|
|
|
- cur_task = await curio.current_task()
|
|
|
- await curio.ignore_after(0,cur_task.join)
|
|
|
- except Exception as e:
|
|
|
- lserver.error("error",exc_info=e)
|
|
|
+ await self.respond(tb,log_msg="traceback of '{}'"
|
|
|
+ .format(e.__cause__))
|
|
|
+ finally:
|
|
|
+ pass
|
|
|
+ if task:
|
|
|
+ lserver.debug("exec: "+task.exception.__cause__)
|
|
|
+
|
|
|
+ digilib.misc.fake_wait_task()
|
|
|
+ cur_task = await curio.current_task()
|
|
|
+ await curio.ignore_after(0,cur_task.join)
|
|
|
+
|
|
|
+ digilib.network._tasks.remove(cur_task)
|
|
|
+
|
|
|
+ async def respond(self,text,*args,log_msg=False):
|
|
|
+ await self.send(text,log_msg)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
async def welcome_client(self):
|
|
|
await self.send("this is the server speaking, hello new client!")
|