Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion p4runtime_sh/p4runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import queue
import sys
import threading
from iterators import TimeoutIterator
from typing import NamedTuple

from p4.v1 import p4runtime_pb2
Expand Down Expand Up @@ -191,6 +192,7 @@ def __init__(self, device_id, grpc_addr, election_id, role_name=None, ssl_option
self.set_up_stream()

def set_up_stream(self):
self.signal_q = queue.Queue()
self.stream_out_q = queue.Queue()
# queues for different messages
self.stream_in_q = {
Expand All @@ -211,7 +213,12 @@ def stream_req_iterator():
def stream_recv_wrapper(stream):
@parse_p4runtime_error
def stream_recv():
for p in stream:
iterator = TimeoutIterator(stream, timeout=1)
for p in iterator:
if not self.signal_q.empty():
break
if p == iterator.get_sentinel():
continue
if p.HasField("arbitration"):
self.stream_in_q["arbitration"].put(p)
elif p.HasField("packet"):
Expand Down Expand Up @@ -304,6 +311,7 @@ def tear_down(self):
for k in self.stream_in_q:
self.stream_in_q[k].put(None)
if self.stream_recv_thread:
self.signal_q.put(None)
self.stream_recv_thread.join()
self.channel.close()
del self.channel # avoid a race condition if channel deleted when process terminates
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ python_requires = >=3.6
setup_requires =
setuptools_scm
install_requires =
iterators == 0.2.0
ipaddr == 2.2.0
jedi == 0.17.2
ipython >= 7.31.1, == 7.31.*; python_version>='3.7'
Expand Down