electrum

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

commit 8fa6bd2aac4a289874cf29494081337796016055
parent e573c6d385a26c68a6da3d0e744a078f8750a18a
Author: SomberNight <somber.night@protonmail.com>
Date:   Fri, 12 Oct 2018 19:03:36 +0200

network: add_job

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

diff --git a/electrum/network.py b/electrum/network.py @@ -188,7 +188,6 @@ class Network(PrintError): self.default_server = pick_random_server() self.main_taskgroup = None - self._jobs = [] # locks self.restart_lock = asyncio.Lock() @@ -791,9 +790,7 @@ class Network(PrintError): with open(path, 'w', encoding='utf-8') as f: f.write(json.dumps(cp, indent=4)) - async def _start(self, jobs=None): - if jobs is None: jobs = self._jobs - self._jobs = jobs + async def _start(self): assert not self.main_taskgroup self.main_taskgroup = SilentTaskGroup() @@ -802,7 +799,7 @@ class Network(PrintError): await self._init_headers_file() async with self.main_taskgroup as group: await group.spawn(self._maintain_sessions()) - [await group.spawn(job) for job in jobs] + [await group.spawn(job) for job in self._jobs] except Exception as e: traceback.print_exc(file=sys.stderr) raise e @@ -818,8 +815,14 @@ class Network(PrintError): self._start_interface(self.default_server) self.trigger_callback('network_updated') - def start(self, jobs=None): - asyncio.run_coroutine_threadsafe(self._start(jobs=jobs), self.asyncio_loop) + def start(self, jobs: List=None): + self._jobs = jobs or [] + asyncio.run_coroutine_threadsafe(self._start(), self.asyncio_loop) + + async def add_job(self, job): + async with self.restart_lock: + self._jobs.append(job) + await self.main_taskgroup.spawn(job) async def _stop(self, full_shutdown=False): self.print_error("stopping network")