Skip to content

Commit efbc1a8

Browse files
committed
disable condition notify
1 parent 80ff148 commit efbc1a8

2 files changed

Lines changed: 33 additions & 25 deletions

File tree

spf/dataset/spf_dataset.py

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from contextlib import contextmanager
1111
from enum import Enum
1212
from functools import cache
13+
from multiprocessing import Queue
1314
from typing import Dict, List
1415

1516
import numpy as np
@@ -488,6 +489,8 @@ def __init__(
488489
self.lock = multiprocessing.Lock()
489490
self.store = {}
490491

492+
self.incoming_queue = multiprocessing.Queue()
493+
491494
self.v4 = v4
492495

493496
# Segmentation parameters control how raw signal is processed into windows
@@ -616,30 +619,38 @@ def __next__(self):
616619
# ASSUMING EVERYTHING WILL BE REQUESTED IN SEQUENCE!!
617620
def __getitem__(self, idx, timeout=10.0):
618621
start_time = time.time()
619-
with self.condition:
620-
print("waitinf to get get", idx, time.time() - start_time)
621-
while idx not in self.store or self.store[idx]["count"] != 2:
622-
self.condition.wait(0.01)
623-
if (time.time() - start_time) > timeout:
624-
print("ret waitinf to get get", idx, time.time() - start_time)
625-
return None
626-
return self.store[idx]["data"]
622+
# with self.condition:
623+
print("waitinf to get get", idx, time.time() - start_time)
624+
while idx not in self.store or self.store[idx]["count"] != 2:
625+
# self.condition.wait(0.01)
626+
self.check_for_new_data()
627+
time.sleep(0.02)
628+
if (time.time() - start_time) > timeout:
629+
print("ret waitinf to get get", idx, time.time() - start_time)
630+
return None
631+
return self.store[idx]["data"]
632+
633+
def check_for_new_data(self):
634+
with self.lock:
635+
while not self.incoming_queue.empty():
636+
# shouldnt wait since we checked above
637+
idx, ridx, rendered_data = self.incoming_queue.get_nowait()
638+
if idx not in self.store:
639+
self.store[idx] = {
640+
"count": 0,
641+
"data": [None, None],
642+
} # entry not ready
643+
self.store[idx]["data"][ridx] = rendered_data
644+
self.store[idx]["count"] += 1
627645

628646
def write_to_idx(self, idx, ridx, raw):
629-
if idx < self.min_idx:
630-
return # we dont need this sample
631-
647+
# this is the heavy lifting of processing, do it on this process
632648
rendered_data = self.render_session(idx, ridx, raw)
633649

634-
self.lock.acquire()
635-
if idx not in self.store:
636-
self.store[idx] = {"count": 0, "data": [None, None]} # entry not ready
637-
self.store[idx]["data"][ridx] = rendered_data
638-
self.store[idx]["count"] += 1
639-
self.lock.release()
650+
self.incoming_queue.put((idx, ridx, rendered_data))
640651

641-
with self.condition:
642-
self.condition.notify_all()
652+
# with self.condition:
653+
# self.condition.notify_all()
643654

644655
def render_session(self, idx, ridx, data):
645656
snapshot_idxs = [0] # which snapshots to get
@@ -694,7 +705,7 @@ def render_session(self, idx, ridx, data):
694705
data["tx_pos_xy"] = (
695706
data["tx_pos_mm"][snapshot_idxs].unsqueeze(0) / self.distance_normalization
696707
)
697-
708+
breakpoint()
698709
segmentation = segment_session(
699710
data["signal_matrix"][0][0].numpy(),
700711
gpu=self.gpu,

spf/mavlink_radio_collection.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,15 @@ def parse_args():
202202
else:
203203
connection = mavutil.mavlink_connection(yaml_config["drone-uri"])
204204
drone = Drone(
205-
connection,
206-
distance_finder=distance_finder,
207-
ignore_mode=args.ignore_mode
205+
connection, distance_finder=distance_finder, ignore_mode=args.ignore_mode
208206
)
209207
drone.start()
210208
else:
211209
drone = Drone(
212210
None,
213211
distance_finder=distance_finder,
214212
fake=True,
215-
ignore_mode=args.ignore_mode
213+
ignore_mode=args.ignore_mode,
216214
)
217215

218216
while not args.fake_drone and not drone.drone_ready:
@@ -221,7 +219,6 @@ def parse_args():
221219
)
222220
time.sleep(10)
223221

224-
225222
boundary_name = yaml_config.get("boundary", "franklin_safe")
226223
if boundary_name == "auto":
227224
# find out which one is closest

0 commit comments

Comments
 (0)