Skip to content

Commit ac789a8

Browse files
committed
gracefully handle GeneratorExit
Signed-off-by: Sam Friedman <[email protected]>
1 parent 3747400 commit ac789a8

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

golioth/golioth.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,10 @@ async def logs_iter(self, lines: int = 0, params: dict = {}) -> Iterable[LogEntr
304304
if log in old_logs:
305305
continue
306306

307-
yield log
307+
try:
308+
yield log
309+
except GeneratorExit as e:
310+
break
308311

309312

310313
class LogLevel(Enum):
@@ -582,7 +585,10 @@ async def monitor(self, path: str, params: dict = {}) -> LightDBMonitor:
582585
async def iter(self, path: str, params: dict = {}) -> Iterable[LightDBMonitor.ValueType]:
583586
async with self.monitor(path, params) as monitor:
584587
while True:
585-
yield await monitor.get()
588+
try:
589+
yield await monitor.get()
590+
except GeneratorExit as e:
591+
break
586592

587593

588594
class DeviceStream(ApiNodeMixin):
@@ -655,8 +661,10 @@ async def monitor(self, params: dict = {}) -> LightDBMonitor:
655661
async def iter(self, params: dict = {}) -> Iterable[LightDBMonitor.ValueType]:
656662
async with self.monitor(params) as monitor:
657663
while True:
658-
yield await monitor.get()
659-
664+
try:
665+
yield await monitor.get()
666+
except GeneratorExit as e:
667+
break
660668

661669
class DeviceRPC(ApiNodeMixin):
662670
def __init__(self, device: Device):

0 commit comments

Comments
 (0)