Skip to content

Commit

Permalink
Fix msgq context overrides (commaai#33014)
Browse files Browse the repository at this point in the history
* Fix msgq context overrides

* Remove unneccesary changes

* add reset_context helper

* Remove redundant import
  • Loading branch information
fredyshox authored Jul 19, 2024
1 parent fd5549b commit c96dbd5
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 9 deletions.
7 changes: 6 additions & 1 deletion cereal/messaging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from msgq.ipc_pyx import Context, Poller, SubSocket, PubSocket, SocketEventHandle, toggle_fake_events, \
set_fake_prefix, get_fake_prefix, delete_fake_prefix, wait_for_one_event
from msgq.ipc_pyx import MultiplePublishersError, IpcError
from msgq import fake_event_handle, pub_sock, sub_sock, drain_sock_raw, context
from msgq import fake_event_handle, pub_sock, sub_sock, drain_sock_raw
import msgq

import os
import capnp
Expand All @@ -17,6 +18,10 @@
NO_TRAVERSAL_LIMIT = 2**64-1


def reset_context():
msgq.context = Context()


def log_from_bytes(dat: bytes, struct: capnp.lib.capnp._StructModule = log.Event) -> capnp.lib.capnp._DynamicStructReader:
with struct.from_bytes(dat, traversal_limit_in_words=NO_TRAVERSAL_LIMIT) as msg:
return msg
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/debug/internal/measure_torque_time_to_max.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

if args.addr != "127.0.0.1":
os.environ["ZMQ"] = "1"
messaging.context = messaging.Context()
messaging.reset_context()

poller = messaging.Poller()
messaging.sub_sock('can', poller, addr=args.addr)
Expand Down
2 changes: 1 addition & 1 deletion system/manager/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def launcher(proc: str, name: str) -> None:
setthreadname(proc)

# create new context since we forked
messaging.context = messaging.Context()
messaging.reset_context()

# add daemon name tag to logs
cloudlog.bind(daemon=name)
Expand Down
7 changes: 4 additions & 3 deletions tools/camerastream/compressed_vipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import time
import signal


import cereal.messaging as messaging
from msgq.visionipc import VisionIpcServer, VisionStreamType

Expand Down Expand Up @@ -42,7 +43,7 @@ def decoder(addr, vipc_server, vst, nvidia, W, H, debug=False):
codec = av.CodecContext.create("hevc", "r")

os.environ["ZMQ"] = "1"
messaging.context = messaging.Context()
messaging.reset_context()
sock = messaging.sub_sock(sock_name, None, addr=addr, conflate=False)
cnt = 0
last_idx = -1
Expand Down Expand Up @@ -109,12 +110,12 @@ class CompressedVipc:
def __init__(self, addr, vision_streams, nvidia=False, debug=False):
print("getting frame sizes")
os.environ["ZMQ"] = "1"
messaging.context = messaging.Context()
messaging.reset_context()
sm = messaging.SubMaster([ENCODE_SOCKETS[s] for s in vision_streams], addr=addr)
while min(sm.recv_frame.values()) == 0:
sm.update(100)
os.environ.pop("ZMQ")
messaging.context = messaging.Context()
messaging.reset_context()

self.vipc_server = VisionIpcServer("camerad")
for vst in vision_streams:
Expand Down
2 changes: 1 addition & 1 deletion tools/lib/live_logreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def raw_live_logreader(services: list[str] = ALL_SERVICES, addr: str = '127.0.0.1') -> RawLogIterable:
if addr != "127.0.0.1":
os.environ["ZMQ"] = "1"
messaging.context = messaging.Context()
messaging.reset_context()

poller = messaging.Poller()

Expand Down
2 changes: 1 addition & 1 deletion tools/replay/rp_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def get_arg_parser():
args = get_arg_parser().parse_args(sys.argv[1:])
if args.ip_address != "127.0.0.1":
os.environ["ZMQ"] = "1"
messaging.context = messaging.Context()
messaging.reset_context()
rr.init("RadarPoints", spawn= True)
rr.log("tracks", rr.AnnotationContext(rerunColorPalette), static=True)
visualize(args.ip_address)
2 changes: 1 addition & 1 deletion tools/tuning/measure_steering_accuracy.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def update(self, sm):
else:
if args.addr != "127.0.0.1":
os.environ["ZMQ"] = "1"
messaging.context = messaging.Context()
messaging.reset_context()

carControl = messaging.sub_sock('carControl', addr=args.addr, conflate=True)
sm = messaging.SubMaster(['carState', 'carControl', 'carOutput', 'controlsState', 'modelV2'], addr=args.addr)
Expand Down

0 comments on commit c96dbd5

Please sign in to comment.