Skip to content
This repository has been archived by the owner on Sep 17, 2020. It is now read-only.

Commit

Permalink
patch eval to use proper tasking system
Browse files Browse the repository at this point in the history
  • Loading branch information
XuaTheGrate committed Oct 23, 2019
1 parent 686610d commit 75bc816
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cogs/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,23 @@ async def eval(self, ctx, *, code_string):
try:
expr = import_expression.compile(code_string, flags=PyCF_ALLOW_TOP_LEVEL_AWAIT)
ret = eval(expr, self._env)
if inspect.isawaitable(ret):
ret = await ret
except SyntaxError:
pass
except Exception as exc:
await ctx.message.add_reaction(self.bot.tick_no)
return await ctx.send_as_paginator(format_exc(exc), codeblock=True)
else:
if inspect.isawaitable(ret):
fut = asyncio.ensure_future(ret, loop=self.bot.loop)
self._evals.append(fut)
try:
with Timer(ctx.message):
ret = await asyncio.wait_for(fut, timeout=self._timeout)
except Exception as exc:
await ctx.message.add_reaction(self.bot.tick_no)
return await ctx.send_as_paginator(format_exc(exc), codeblock=True)
finally:
self._evals.remove(fut)
await ctx.message.add_reaction(self.bot.tick_yes)
if ret is None:
return
Expand Down

0 comments on commit 75bc816

Please sign in to comment.