network: handle main_taskgroup dying better. passthrough CancelledError
Previously if a task running in the main_taskgroup raised, main_taskgroup might have never finished as fx.run (another task running in main_taskgroup) could not be cancelled (it was swallowing the CancelledError). Need to be careful with catching all Exceptions or BaseExceptions, as that might result in a coroutine not being cancellable. Note that from python 3.8 onwards, CancelledError will inherit from BaseException instead of Exception, so catching all Exceptions is somewhat less horrible but this will only really matter if we raise the min py version to 3.8... Really, all "except BaseException" lines are suspect and at least should be considered for replacement with "except Exception". ----- regarding fx.run not being cancellable before, and relevant lines, see:6197cfbb3b/electrum/network.py (L1171)0decdffce2/aiorpcx/curio.py (L242)0decdffce2/aiorpcx/curio.py (L199)0decdffce2/aiorpcx/curio.py (L208)0decdffce2/aiorpcx/curio.py (L218)0decdffce2/aiorpcx/curio.py (L221)6197cfbb3b/electrum/daemon.py (L194)6197cfbb3b/electrum/daemon.py (L203)6197cfbb3b/electrum/exchange_rate.py (L507)6197cfbb3b/electrum/exchange_rate.py (L79)
This commit is contained in:
@@ -1169,8 +1169,8 @@ class Network(Logger):
|
||||
async with main_taskgroup as group:
|
||||
await group.spawn(self._maintain_sessions())
|
||||
[await group.spawn(job) for job in self._jobs]
|
||||
except Exception as e:
|
||||
self.logger.exception('')
|
||||
except BaseException as e:
|
||||
self.logger.exception('main_taskgroup died.')
|
||||
raise e
|
||||
asyncio.run_coroutine_threadsafe(main(), self.asyncio_loop)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user