Skip to content

Commit 2d1586d

Browse files
committed
Merge branch 'ct-paho-2' of https://github.com/Azure/azure-iot-sdk-python into ct-paho-2
2 parents dcea094 + 8e2c3a8 commit 2d1586d

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

dev_utils/dev_utils/service_helper.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import asyncio
66
import concurrent.futures
77

8+
# TODO: Consider removing injectable executors.
9+
810

911
class ServiceHelper:
1012
def __init__(
@@ -14,6 +16,7 @@ def __init__(
1416
eventhub_consumer_group,
1517
executor=None,
1618
):
19+
self._owns_executor = executor is None
1720
self._executor = executor or concurrent.futures.ThreadPoolExecutor()
1821
self._inner_object = ServiceHelperSync(
1922
iothub_connection_string, eventhub_connection_string, eventhub_consumer_group
@@ -66,4 +69,8 @@ async def get_next_reported_patch_arrival(self, block=True, timeout=240):
6669
)
6770

6871
async def shutdown(self):
69-
return await self._run_in_executor(self._inner_object.shutdown)
72+
await self._run_in_executor(self._inner_object.shutdown)
73+
74+
if self._owns_executor:
75+
self._executor.shutdown(wait=True)
76+
return

dev_utils/dev_utils/service_helper_sync.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,16 @@ def shutdown(self):
201201
if self._eventhub_consumer_client:
202202
self._eventhub_consumer_client.close()
203203

204+
if self._eventhub_future:
205+
try:
206+
# Ensure the EventHub receive loop exits before tearing down the executor
207+
self._eventhub_future.result(timeout=30)
208+
except Exception:
209+
logger.warning("_eventhub_thread did not exit cleanly", exc_info=True)
210+
211+
if self._executor:
212+
self._executor.shutdown(wait=True)
213+
204214
def _convert_incoming_event(self, event):
205215
try:
206216
event_body = event.body_as_json()

tests/e2e/iothub_e2e/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ def transport():
4343

4444
@pytest.fixture(scope="session")
4545
def executor():
46-
return concurrent.futures.ThreadPoolExecutor()
46+
executor = concurrent.futures.ThreadPoolExecutor()
47+
yield executor
48+
executor.shutdown()
4749

4850

4951
@pytest.fixture(scope="function")

0 commit comments

Comments
 (0)