mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 16:10:57 +00:00
Remove locks in PubsubNotifee
- Change `open_memory_channel(0)` to `open_memory_channel(math.inf)`, to avoid `peer_queue.send` and `dead_peer_queue.send` blocking. This allows us to remove the locks. - Only catch `trio.BrokenResourceError`, which is caused by Pubsub when it's closing.
This commit is contained in:
@ -95,15 +95,15 @@ class Pubsub(Service, IPubsub):
|
||||
# Attach this new Pubsub object to the router
|
||||
self.router.attach(self)
|
||||
|
||||
peer_channels = trio.open_memory_channel[ID](0)
|
||||
dead_peer_channels = trio.open_memory_channel[ID](0)
|
||||
peer_send, peer_receive = trio.open_memory_channel[ID](math.inf)
|
||||
dead_peer_send, dead_peer_receive = trio.open_memory_channel[ID](math.inf)
|
||||
# Only keep the receive channels in `Pubsub`.
|
||||
# Therefore, we can only close from the receive side.
|
||||
self.peer_receive_channel = peer_channels[1]
|
||||
self.dead_peer_receive_channel = dead_peer_channels[1]
|
||||
self.peer_receive_channel = peer_receive
|
||||
self.dead_peer_receive_channel = dead_peer_receive
|
||||
# Register a notifee
|
||||
self.host.get_network().register_notifee(
|
||||
PubsubNotifee(peer_channels[0], dead_peer_channels[0])
|
||||
PubsubNotifee(peer_send, dead_peer_send)
|
||||
)
|
||||
|
||||
# Register stream handlers for each pubsub router protocol to handle
|
||||
|
||||
Reference in New Issue
Block a user