Exceptions now also work over the subprocess.

This commit is contained in:
Dave Halter
2017-11-17 01:54:05 +01:00
parent 4a7d715a57
commit 87452639ad
3 changed files with 13 additions and 2 deletions

View File

@@ -51,6 +51,9 @@ class CheckAttribute(object):
self.check_name = func.__name__[2:]
def __get__(self, instance, owner):
if instance is None:
return self
# This might raise an AttributeError. That's wanted.
if self.check_name == '__iter__':
# Python iterators are a bit strange, because there's no need for

View File

@@ -98,7 +98,10 @@ class _Subprocess(object):
data = evaluator_id, function, args, kwargs
pickle.dump(data, self._process.stdin, protocol=_PICKLE_PROTOCOL)
self._process.stdin.flush()
return pickle.load(self._process.stdout)
is_exception, result = pickle.load(self._process.stdout)
if is_exception:
raise result
return result
def terminate(self):
self._process.terminate()
@@ -167,7 +170,10 @@ class Listener():
# It looks like the parent process closed. Don't make a big fuss
# here and just exit.
exit(1)
result = self._run(*payload)
try:
result = False, self._run(*payload)
except Exception as e:
result = True, e
pickle.dump(result, stdout, protocol=_PICKLE_PROTOCOL)
stdout.flush()

View File

@@ -36,3 +36,5 @@ def test_import_module(evaluator):
compiled_obj = evaluator.compiled_subprocess.import_module(name='math')
assert compiled_obj.py__bool__() is True
assert compiled_obj.type == 'file_input'
with pytest.raises(AttributeError):
assert compiled_obj.py__mro__()