diff --git a/sysbrokers/IB/ib_connection.py b/sysbrokers/IB/ib_connection.py index 1244082fb8..da49e72e51 100644 --- a/sysbrokers/IB/ib_connection.py +++ b/sysbrokers/IB/ib_connection.py @@ -88,6 +88,9 @@ def __init__( def __repr__(self): return "IB broker connection" + str(self._ib_connection_config) + def client_id(self): + return self._ib_connection_config["client"] + def close_connection(self): self.log.msg("Terminating %s" % str(self._ib_connection_config)) try: @@ -97,8 +100,5 @@ def close_connection(self): self.log.warn( "Trying to disconnect IB client failed... ensure process is killed" ) - finally: - self.db_id_tracker.release_clientid( - self._ib_connection_config["client"]) diff --git a/sysdata/data_blob.py b/sysdata/data_blob.py index 82a4eba8ad..2a1de1f57e 100644 --- a/sysdata/data_blob.py +++ b/sysdata/data_blob.py @@ -229,6 +229,8 @@ def __exit__(self, exc_type, exc_val, exc_tb): def close(self): if self._ib_conn is not arg_not_supplied: self.ib_conn.close_connection() + self.db_ib_broker_client_id.release_clientid( + self.ib_conn.client_id()) # No need to explicitly close Mongo connections; handled by Python garbage collection