vici: Catch Python GeneratorExit to properly cancel streamed event iteration
This commit is contained in:
parent
288b654173
commit
90c5b48c96
|
@ -909,6 +909,11 @@ event:
|
|||
for key in conn:
|
||||
print key
|
||||
|
||||
Please note that if the returned generator is not iterated completely, it must
|
||||
be closed using _close()_. This is implicitly done when breaking from a loop,
|
||||
but an explicit call may be required when directly iterating the generator with
|
||||
_next()_.
|
||||
|
||||
## Sorting in dictionaries ##
|
||||
|
||||
In VICI, in some message trees the order of objects in dictionary matters. In
|
||||
|
|
|
@ -281,10 +281,16 @@ class SessionHandler(object):
|
|||
# issue command, and read any event messages
|
||||
packet = Packet.request(command, message)
|
||||
self.transport.send(packet)
|
||||
exited = False
|
||||
while True:
|
||||
response = Packet.parse(self.transport.receive())
|
||||
if response.response_type == Packet.EVENT:
|
||||
yield Message.deserialize(response.payload)
|
||||
if not exited:
|
||||
try:
|
||||
yield Message.deserialize(response.payload)
|
||||
except GeneratorExit:
|
||||
exited = True
|
||||
pass
|
||||
else:
|
||||
break
|
||||
|
||||
|
|
Loading…
Reference in New Issue