From e612f9363118d5e53e8597a369195f100a49b9b9 Mon Sep 17 00:00:00 2001 From: Vadim Ushakov Date: Sat, 23 Oct 2021 21:41:14 +0700 Subject: [PATCH] Spawn message loops for outgoing connections in a sepatare pool managed by ConnectionServer --- src/Connection/Connection.py | 2 +- src/Connection/ConnectionServer.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Connection/Connection.py b/src/Connection/Connection.py index 4a7c6ab9..398a4cc3 100644 --- a/src/Connection/Connection.py +++ b/src/Connection/Connection.py @@ -167,7 +167,7 @@ class Connection(object): # Detect protocol event_connected = self.event_connected self.send({"cmd": "handshake", "req_id": 0, "params": self.getHandshakeInfo()}) - gevent.spawn(self.messageLoop) + self.server.outgoing_pool.spawn(self.messageLoop) connect_res = event_connected.get() # Wait for handshake if self.sock: self.sock.settimeout(timeout_before) diff --git a/src/Connection/ConnectionServer.py b/src/Connection/ConnectionServer.py index e7951321..03a93daa 100644 --- a/src/Connection/ConnectionServer.py +++ b/src/Connection/ConnectionServer.py @@ -79,6 +79,9 @@ class ConnectionServer(object): self.pool = Pool(500) # do not accept more than 500 connections self.managed_pools["incoming"] = self.pool + self.outgoing_pool = Pool(None) + self.managed_pools["outgoing"] = self.outgoing_pool + # Bittorrent style peerid self.peer_id = "-UT3530-%s" % CryptHash.random(12, "base64")