mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-24 03:29:28 +01:00
src/commands.py: make subprocesses raise an error on timeout, rather than return a string
This commit is contained in:
parent
08e676e8fe
commit
2feaddba08
@ -69,6 +69,10 @@ def thread(f):
|
|||||||
f(self, irc, msg, args, *L, **kwargs)
|
f(self, irc, msg, args, *L, **kwargs)
|
||||||
return utils.python.changeFunctionName(newf, f.func_name, f.__doc__)
|
return utils.python.changeFunctionName(newf, f.func_name, f.__doc__)
|
||||||
|
|
||||||
|
class ProcessTimeoutError(Exception):
|
||||||
|
"""Gets raised when a process is killed due to timeout."""
|
||||||
|
pass
|
||||||
|
|
||||||
def process(f, *args, **kwargs):
|
def process(f, *args, **kwargs):
|
||||||
"""Runs a function <f> in a subprocess.
|
"""Runs a function <f> in a subprocess.
|
||||||
|
|
||||||
@ -93,7 +97,7 @@ def process(f, *args, **kwargs):
|
|||||||
p.join(timeout)
|
p.join(timeout)
|
||||||
if p.is_alive():
|
if p.is_alive():
|
||||||
p.terminate()
|
p.terminate()
|
||||||
return "%s aborted due to timeout." % (p.name,)
|
raise ProcessTimeoutError, "%s aborted due to timeout." % (p.name,)
|
||||||
try:
|
try:
|
||||||
v = q.get(block=False)
|
v = q.get(block=False)
|
||||||
except Queue.Empty:
|
except Queue.Empty:
|
||||||
|
Loading…
Reference in New Issue
Block a user