Skip to content

Commit 7536e4a

Browse files
committed
ServerBase now detect hearbeat RemoteLost properly
1 parent f08e0ad commit 7536e4a

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

zerorpc/core.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import gevent.coros
3434

3535
import gevent_zmq as zmq
36-
from .exceptions import TimeoutExpired, RemoteError
36+
from .exceptions import TimeoutExpired, RemoteError, LostRemote
3737
from .channel import ChannelMultiplexer, BufferedChannel
3838
from .socket import SocketBase
3939
from .heartbeat import HeartBeatOnChannel
@@ -105,34 +105,39 @@ def __call__(self, method, *args):
105105
raise NameError(method)
106106
return self._methods[method](*args)
107107

108+
def _print_traceback(self, protocol_v1):
109+
exc_type, exc_value, exc_traceback = sys.exc_info()
110+
try:
111+
traceback.print_exception(exc_type, exc_value, exc_traceback,
112+
file=sys.stderr)
113+
114+
if protocol_v1:
115+
return (repr(exc_value),)
116+
117+
human_traceback = traceback.format_exc()
118+
name = exc_type.__name__
119+
human_msg = str(exc_value)
120+
return (name, human_msg, human_traceback)
121+
finally:
122+
del exc_traceback
123+
108124
def _async_task(self, initial_event):
109-
protocol_v2 = initial_event.header.get('v', 1) >= 2
125+
protocol_v1 = initial_event.header.get('v', 1) < 2
110126
channel = self._multiplexer.channel(initial_event)
111127
hbchan = HeartBeatOnChannel(channel, freq=self._heartbeat_freq,
112-
passive=not protocol_v2)
128+
passive=protocol_v1)
113129
bufchan = BufferedChannel(hbchan)
114130
event = bufchan.recv()
115131
try:
116132
functor = self._methods.get(event.name, None)
117133
if functor is None:
118134
raise NameError(event.name)
119135
functor.pattern.process_call(self._context, bufchan, event, functor)
136+
except LostRemote:
137+
self._print_traceback(protocol_v1)
120138
except Exception:
121-
try:
122-
exc_type, exc_value, exc_traceback = sys.exc_info()
123-
traceback.print_exception(exc_type, exc_value, exc_traceback,
124-
file=sys.stderr)
125-
human_traceback = traceback.format_exc()
126-
127-
name = exc_type.__name__
128-
human_msg = str(exc_value)
129-
130-
if protocol_v2:
131-
bufchan.emit('ERR', (name, human_msg, human_traceback))
132-
else:
133-
bufchan.emit('ERR', (repr(exc_value),))
134-
finally:
135-
del exc_traceback
139+
exception_info = self._print_traceback(protocol_v1)
140+
bufchan.emit('ERR', exception_info)
136141
finally:
137142
bufchan.close()
138143
bufchan.channel.close()

0 commit comments

Comments
 (0)