Skip to content

Commit f0e39ad

Browse files
author
Axel Dahlberg
committed
If a CQCConnection does not manage to connect to the cqc server, the used app ID is popped from the list of used ones, to be reused again
1 parent 307989a commit f0e39ad

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

cqc/pythonLib.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def __init__(self, name, socket_address=None, appID=None, pend_messages=False,
243243
self._appID = appID
244244
self._appIDs[name].append(self._appID)
245245

246-
# Buffer received data
246+
# Buffer received data
247247
self.buf = None
248248

249249
# ClassicalServer
@@ -302,6 +302,7 @@ def __init__(self, name, socket_address=None, appID=None, pend_messages=False,
302302
time.sleep(self._conn_retry_time)
303303
self._s.close()
304304
if not retry_connection:
305+
self.close(release_qubits=False)
305306
raise err
306307
except Exception as err:
307308
logging.warning("App {} : Critical error when connection to CQC server: {}".format(self.name, err))
@@ -349,21 +350,27 @@ def get_appID(self):
349350

350351
def close(self, release_qubits=True):
351352
"""
352-
Closes the connection. Releases all qubits
353+
Closes the connection. Releases all qubits and remove the app ID from the used app IDs.
353354
"""
354355
if release_qubits:
355356
self.release_all_qubits()
356357
self._s.close()
357-
try:
358-
self._appIDs[self.name].remove(self._appID)
359-
except ValueError:
360-
pass # Already closed
358+
self._pop_app_id()
361359

362360
self.closeClassicalServer()
363361

364362
for name in list(self._classicalConn):
365363
self.closeClassicalChannel(name)
366364

365+
def _pop_app_id(self):
366+
"""
367+
Removes the used appID from the list.
368+
"""
369+
try:
370+
self._appIDs[self.name].remove(self._appID)
371+
except ValueError:
372+
pass # Already removed
373+
367374
def startClassicalServer(self):
368375
"""
369376
Sets up a server for the application communication, if not already set up.

0 commit comments

Comments
 (0)