Skip to content

Commit 32f48e3

Browse files
authored
Merge pull request #79 from telefonicasc/kevin/finally-in-etl
feat: del and init handle warning
2 parents c577917 + 3a31f13 commit 32f48e3

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

python-lib/tc_etl_lib/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,8 @@ TOTAL 403 221 45%
505505

506506
## Changelog
507507

508+
- Fix: close session upon finalization to avoid warnings ([#76](https://github.com/telefonicasc/etl-framework/pull/76))
509+
508510
0.10.0 (November 29th, 2023)
509511

510512
- Add: new class `iotaManager` to deal with IoT Agent interactions, with methods `send_http` and `send_batch_http`([#55](https://github.com/telefonicasc/etl-framework/issues/55))

python-lib/tc_etl_lib/tc_etl_lib/cb.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class cbManager:
7272
# reasons other than block size (e.g to avoid triggering too
7373
# many subscriptions per batch and stressing cygnus queues)
7474
batch_size = 0
75+
session = None
7576

7677
def __init__(self,*, endpoint: Optional[str] = None, timeout: int = 10, post_retry_connect: int = 3, post_retry_backoff_factor: int = 20, sleep_send_batch: int = 0, cb_flowcontrol: bool = False, block_size: int = 800000, batch_size: int = 0) -> None:
7778

@@ -85,13 +86,19 @@ def __init__(self,*, endpoint: Optional[str] = None, timeout: int = 10, post_ret
8586
self.sleep_send_batch = sleep_send_batch
8687
self.cb_flowcontrol = cb_flowcontrol
8788
self.batch_size = batch_size
89+
self.session = requests.Session()
8890

8991
# check block_size limit.
9092
if (int(block_size) > int(800000)):
9193
raise ValueError('Block size limit reached! <<block_size>> value cannot be greater than 800000')
9294

9395
self.block_size = block_size
9496

97+
def __del__(self):
98+
try:
99+
self.session.close()
100+
except Exception: # pylint: disable=broad-except
101+
logger.error(f'Error closing session with endpoint: {self.endpoint}')
95102

96103
def delete_entities(self, *, service: str = None, subservice: str = None, auth: authManager = None, limit: int = 100, type: str = None, q: str = None, mq: str = None, georel: str = None, geometry: str = None, coords: str = None, id: str = None, options_get: list = [], options_send: list = []):
97104
"""Delete data from context broker
@@ -390,7 +397,7 @@ def __batch_creation(self, *, service: str = None, subservice: str = None, auth:
390397
else:
391398
req_url = f"{self.endpoint}/v2/op/update"
392399

393-
http = requests.Session()
400+
http = self.session
394401
retry_strategy = Retry(
395402
total=self.post_retry_connect,
396403
read=self.post_retry_connect,

0 commit comments

Comments
 (0)