mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-09-11 10:56:14 +03:00
Set keychain_proxy to None in await_closed() to support reinitialization (#11075)
* Set keychain_proxy to None in await_closed() to support reinitialization. * Added `shutting_down` param to _await_closed() to control whether the keychain_proxy is closed.
This commit is contained in:
parent
c238ce17ba
commit
d35c414c09
@ -140,7 +140,7 @@ class Farmer:
|
||||
self.harvester_cache: Dict[str, Dict[str, HarvesterCacheEntry]] = {}
|
||||
|
||||
async def ensure_keychain_proxy(self) -> KeychainProxy:
|
||||
if not self.keychain_proxy:
|
||||
if self.keychain_proxy is None:
|
||||
if self.local_keychain:
|
||||
self.keychain_proxy = wrap_local_keychain(self.local_keychain, log=self.log)
|
||||
else:
|
||||
@ -212,13 +212,15 @@ class Farmer:
|
||||
def _close(self):
|
||||
self._shut_down = True
|
||||
|
||||
async def _await_closed(self):
|
||||
async def _await_closed(self, shutting_down: bool = True):
|
||||
if self.cache_clear_task is not None:
|
||||
await self.cache_clear_task
|
||||
if self.update_pool_state_task is not None:
|
||||
await self.update_pool_state_task
|
||||
if self.keychain_proxy is not None:
|
||||
await self.keychain_proxy.close()
|
||||
if shutting_down and self.keychain_proxy is not None:
|
||||
proxy = self.keychain_proxy
|
||||
self.keychain_proxy = None
|
||||
await proxy.close()
|
||||
await asyncio.sleep(0.5) # https://docs.aiohttp.org/en/stable/client_advanced.html#graceful-shutdown
|
||||
self.started = False
|
||||
|
||||
|
@ -157,7 +157,7 @@ class WalletRpcApi:
|
||||
"""
|
||||
if self.service is not None:
|
||||
self.service._close()
|
||||
peers_close_task: Optional[asyncio.Task] = await self.service._await_closed()
|
||||
peers_close_task: Optional[asyncio.Task] = await self.service._await_closed(shutting_down=False)
|
||||
if peers_close_task is not None:
|
||||
await peers_close_task
|
||||
|
||||
|
@ -143,7 +143,7 @@ class WalletNode:
|
||||
self.LONG_SYNC_THRESHOLD = 200
|
||||
|
||||
async def ensure_keychain_proxy(self) -> KeychainProxy:
|
||||
if not self.keychain_proxy:
|
||||
if self.keychain_proxy is None:
|
||||
if self.local_keychain:
|
||||
self.keychain_proxy = wrap_local_keychain(self.local_keychain, log=self.log)
|
||||
else:
|
||||
@ -259,7 +259,7 @@ class WalletNode:
|
||||
if self._secondary_peer_sync_task is not None:
|
||||
self._secondary_peer_sync_task.cancel()
|
||||
|
||||
async def _await_closed(self):
|
||||
async def _await_closed(self, shutting_down: bool = True):
|
||||
self.log.info("self._await_closed")
|
||||
|
||||
if self.server is not None:
|
||||
@ -269,8 +269,10 @@ class WalletNode:
|
||||
if self.wallet_state_manager is not None:
|
||||
await self.wallet_state_manager._await_closed()
|
||||
self.wallet_state_manager = None
|
||||
if self.keychain_proxy is not None:
|
||||
await self.keychain_proxy.close()
|
||||
if shutting_down and self.keychain_proxy is not None:
|
||||
proxy = self.keychain_proxy
|
||||
self.keychain_proxy = None
|
||||
await proxy.close()
|
||||
await asyncio.sleep(0.5) # https://docs.aiohttp.org/en/stable/client_advanced.html#graceful-shutdown
|
||||
self.logged_in = False
|
||||
self.wallet_peers = None
|
||||
|
Loading…
Reference in New Issue
Block a user