mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-10-08 01:40:31 +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)
|
server_uri = 'PYRO:server@{host}:{port}'.format(host=host, port=port)
|
||||||
connection = Pyro4.Proxy(server_uri)
|
connection = Pyro4.Proxy(server_uri)
|
||||||
|
|
||||||
log.debug('Connecting to the RPC daemon')
|
log.debug('Connecting to 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
|
|
||||||
|
|
||||||
|
connected = False
|
||||||
try:
|
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
|
yield connection
|
||||||
finally:
|
finally:
|
||||||
log.debug('Stopping the RPC daemon')
|
if connected:
|
||||||
connection.stop()
|
log.debug('Stopping RPC daemon')
|
||||||
connection._pyroRelease()
|
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