Browse Source

network: add_job

3.3.3.1
SomberNight 6 years ago
parent
commit
8fa6bd2aac
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 17
      electrum/network.py

17
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")

Loading…
Cancel
Save