electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 92ad7ec5c0e009fd31ca08cc2745a67853d4bd88
parent e63157c2abdf79800b1485fa74a51f7c48b3842e
Author: SomberNight <somber.night@protonmail.com>
Date:   Tue,  7 May 2019 17:24:00 +0200

interface: use itertools.count

Diffstat:
Melectrum/interface.py | 10+++-------
1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/electrum/interface.py b/electrum/interface.py @@ -31,6 +31,7 @@ import asyncio from typing import Tuple, Union, List, TYPE_CHECKING, Optional from collections import defaultdict from ipaddress import IPv4Network, IPv6Network, ip_address +import itertools import aiorpcx from aiorpcx import RPCSession, Notification, NetAddress @@ -75,15 +76,10 @@ class NotificationSession(RPCSession): self.subscriptions = defaultdict(list) self.cache = {} self.default_timeout = NetworkTimeout.Generic.NORMAL - self._msg_counter = 0 + self._msg_counter = itertools.count(start=1) self.interface = None # type: Optional[Interface] self.cost_hard_limit = 0 # disable aiorpcx resource limits - def _get_and_inc_msg_counter(self): - # runs in event loop thread, no need for lock - self._msg_counter += 1 - return self._msg_counter - async def handle_request(self, request): self.maybe_log(f"--> {request}") try: @@ -105,7 +101,7 @@ class NotificationSession(RPCSession): async def send_request(self, *args, timeout=None, **kwargs): # note: semaphores/timeouts/backpressure etc are handled by # aiorpcx. the timeout arg here in most cases should not be set - msg_id = self._get_and_inc_msg_counter() + msg_id = next(self._msg_counter) self.maybe_log(f"<-- {args} {kwargs} (id: {msg_id})") try: response = await asyncio.wait_for(