mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-10-07 17:40:30 +00:00
Better termination when exiting while connecting to the RPC daemon
This commit is contained in:
parent
9505110d4a
commit
4582ea1498
1 changed files with 21 additions and 16 deletions
|
@ -103,23 +103,28 @@ def connect_pyro(host, port):
|
|||
server_uri = 'PYRO:server@{host}:{port}'.format(host=host, port=port)
|
||||
connection = Pyro4.Proxy(server_uri)
|
||||
|
||||
log.debug('Connecting to the RPC daemon')
|
||||
remaining_retries = 5
|
||||
while True:
|
||||
try:
|
||||
connection.ping()
|
||||
break
|
||||
except (Pyro4.errors.ConnectionClosedError, Pyro4.errors.CommunicationError):
|
||||
if remaining_retries > 0:
|
||||
remaining_retries -= 1
|
||||
from time import sleep
|
||||
sleep(2)
|
||||
else:
|
||||
raise
|
||||
log.debug('Connecting to RPC daemon')
|
||||
|
||||
connected = False
|
||||
try:
|
||||
remaining_retries = 5
|
||||
while not connected:
|
||||
try:
|
||||
connection.ping()
|
||||
connected = True
|
||||
except (Pyro4.errors.ConnectionClosedError, Pyro4.errors.CommunicationError):
|
||||
if remaining_retries > 0:
|
||||
remaining_retries -= 1
|
||||
from time import sleep
|
||||
sleep(2)
|
||||
else:
|
||||
raise
|
||||
|
||||
yield connection
|
||||
finally:
|
||||
log.debug('Stopping the RPC daemon')
|
||||
connection.stop()
|
||||
connection._pyroRelease()
|
||||
if connected:
|
||||
log.debug('Stopping RPC daemon')
|
||||
connection.stop()
|
||||
connection._pyroRelease()
|
||||
else:
|
||||
log.warn('Unable to stop RPC daemon, it might still be running on the server')
|
||||
|
|
Loading…
Add table
Reference in a new issue