Synchronize packet listeners during hot reload
This commit is contained in:
1 parent
05941f500a
commit
f92d3a09bf
1 file changed
+5
@@ -133,6 +133,7 @@ class Connection(object):
|
||||
# This lock is re-entrant because it may be acquired in a re-entrant
|
||||
# manner from within an outgoing packet
|
||||
self._write_lock = RLock()
|
||||
self.packet_listener_lock = RLock()
|
||||
|
||||
self.networking_thread = None
|
||||
self.new_networking_thread = None
|
||||
@@ -274,6 +275,7 @@ class Connection(object):
|
||||
else self.early_packet_listeners if early and not outgoing \
|
||||
else self.outgoing_packet_listeners if not early \
|
||||
else self.early_outgoing_packet_listeners
|
||||
with self.packet_listener_lock:
|
||||
target.append(packets.PacketListener(method, *packet_types, **kwds))
|
||||
|
||||
def register_exception_handler(self, handler_func, *exc_types, **kwds):
|
||||
@@ -587,6 +589,9 @@ class Connection(object):
|
||||
self.handle_exit()
|
||||
|
||||
def _react(self, packet):
|
||||
# Let live code reload replace bound listeners without racing a packet
|
||||
# dispatch. RLock permits handlers to register listeners themselves.
|
||||
with self.packet_listener_lock:
|
||||
try:
|
||||
for listener in self.early_packet_listeners:
|
||||
listener.call_packet(packet)
|
||||
|
||||
Reference in new issue
Block a user