提交 c3b34fd9 编写于 作者: H Hongsheng Zeng 提交者: Bo Zhou

add exception traceback of remote function calling (#79)

* add traceback of remote function calling

* assert traceback information
上级 48fc1de8
...@@ -16,6 +16,7 @@ import numpy as np ...@@ -16,6 +16,7 @@ import numpy as np
import pyarrow import pyarrow
import threading import threading
import time import time
import traceback
import zmq import zmq
from parl.remote import remote_constants from parl.remote import remote_constants
from parl.utils import get_ip_address, logger, to_str, to_byte from parl.utils import get_ip_address, logger, to_str, to_byte
...@@ -179,7 +180,7 @@ def remote_class(cls): ...@@ -179,7 +180,7 @@ def remote_class(cls):
except Exception as e: except Exception as e:
error_str = str(e) error_str = str(e)
logger.error(e) logger.error(error_str)
if type(e) == AttributeError: if type(e) == AttributeError:
self.reply_socket.send_multipart([ self.reply_socket.send_multipart([
...@@ -197,9 +198,12 @@ def remote_class(cls): ...@@ -197,9 +198,12 @@ def remote_class(cls):
to_byte(error_str) to_byte(error_str)
]) ])
else: else:
traceback_str = str(traceback.format_exc())
logger.error('traceback:\n{}'.format(traceback_str))
self.reply_socket.send_multipart([ self.reply_socket.send_multipart([
remote_constants.EXCEPTION_TAG, remote_constants.EXCEPTION_TAG,
to_byte(error_str) to_byte(error_str + '\ntraceback:\n' +
traceback_str)
]) ])
continue continue
......
...@@ -50,6 +50,9 @@ class Simulator: ...@@ -50,6 +50,9 @@ class Simulator:
value += 1 value += 1
return value return value
def will_raise_exeception_func(self):
x = 1 / 0
class TestRemote(unittest.TestCase): class TestRemote(unittest.TestCase):
def _setUp(self, server_port): def _setUp(self, server_port):
...@@ -91,7 +94,8 @@ class TestRemote(unittest.TestCase): ...@@ -91,7 +94,8 @@ class TestRemote(unittest.TestCase):
try: try:
remote_sim.get_arg3() remote_sim.get_arg3()
except RemoteAttributeError: except RemoteAttributeError as e:
logger.info('Expected exception: {}'.format(e))
# expected # expected
return return
...@@ -105,7 +109,8 @@ class TestRemote(unittest.TestCase): ...@@ -105,7 +109,8 @@ class TestRemote(unittest.TestCase):
try: try:
remote_sim.set_arg3(3) remote_sim.set_arg3(3)
except RemoteAttributeError: except RemoteAttributeError as e:
logger.info('Expected exception: {}'.format(e))
# expected # expected
return return
...@@ -119,7 +124,8 @@ class TestRemote(unittest.TestCase): ...@@ -119,7 +124,8 @@ class TestRemote(unittest.TestCase):
try: try:
remote_sim.set_arg1(wrong_arg=1) remote_sim.set_arg1(wrong_arg=1)
except RemoteError: except RemoteError as e:
logger.info('Expected exception: {}'.format(e))
# expected # expected
return return
...@@ -277,6 +283,22 @@ class TestRemote(unittest.TestCase): ...@@ -277,6 +283,22 @@ class TestRemote(unittest.TestCase):
for t in threads: for t in threads:
t.join() t.join()
def test_remote_object_with_call_raise_exception_function(self):
server_port = 17781
self._setUp(server_port)
remote_sim = self.remote_manager.get_remote()
try:
remote_sim.will_raise_exeception_func()
except RemoteError as e:
assert 'Traceback (most recent call last)' in str(e)
logger.info('Expected exception: {}'.format(e))
# expected
return
assert False
def _run_remote_add(self, remote_sim): def _run_remote_add(self, remote_sim):
value = 0 value = 0
for i in range(1000): for i in range(1000):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册