Browse Source
Prior to this commit, in case an RPC failure occurred when accesing the block height, the program would continue but the wallet would be in an un-writeable state (for command line programs, specifically yield generators; for Qt the shutdown would occur). This commit slightly cleans up the process of shutting down, ensuring that duplicate shutdown calls do not result in stack traces. It also ensures that also for command line programs, the application will immediately shutdown if the regular heartbeat call to query the block height fails, as this risks inconsistencies in the wallet (though the previous situation luckily did not result in this as the call to BaseWallet.close() resulted in the wallet being read only). A future PR should develop a more sophisticated approach to RPC call failures that may allow the program to wait. stopservicemaster
6 changed files with 50 additions and 12 deletions
@ -0,0 +1,18 @@
|
||||
|
||||
from twisted.internet.error import ReactorNotRunning, AlreadyCancelled |
||||
from twisted.internet import reactor |
||||
|
||||
def stop_reactor(): |
||||
""" Both in startup and shutdown, |
||||
the value of the bool `reactor.running` |
||||
does not reliably tell us whether the |
||||
reactor is running (!). There are startup |
||||
and shutdown phases not reported externally |
||||
by IReactorCore. |
||||
Hence the Exception catch is needed here. |
||||
""" |
||||
try: |
||||
if reactor.running: |
||||
reactor.stop() |
||||
except ReactorNotRunning: |
||||
pass |
||||
Loading…
Reference in new issue