|
10 | 10 | from contextlib import contextmanager |
11 | 11 | from enum import Enum |
12 | 12 | from functools import cache |
| 13 | +from multiprocessing import Queue |
13 | 14 | from typing import Dict, List |
14 | 15 |
|
15 | 16 | import numpy as np |
@@ -488,6 +489,8 @@ def __init__( |
488 | 489 | self.lock = multiprocessing.Lock() |
489 | 490 | self.store = {} |
490 | 491 |
|
| 492 | + self.incoming_queue = multiprocessing.Queue() |
| 493 | + |
491 | 494 | self.v4 = v4 |
492 | 495 |
|
493 | 496 | # Segmentation parameters control how raw signal is processed into windows |
@@ -616,30 +619,38 @@ def __next__(self): |
616 | 619 | # ASSUMING EVERYTHING WILL BE REQUESTED IN SEQUENCE!! |
617 | 620 | def __getitem__(self, idx, timeout=10.0): |
618 | 621 | 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 |
627 | 645 |
|
628 | 646 | 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 |
632 | 648 | rendered_data = self.render_session(idx, ridx, raw) |
633 | 649 |
|
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)) |
640 | 651 |
|
641 | | - with self.condition: |
642 | | - self.condition.notify_all() |
| 652 | + # with self.condition: |
| 653 | + # self.condition.notify_all() |
643 | 654 |
|
644 | 655 | def render_session(self, idx, ridx, data): |
645 | 656 | snapshot_idxs = [0] # which snapshots to get |
@@ -694,7 +705,7 @@ def render_session(self, idx, ridx, data): |
694 | 705 | data["tx_pos_xy"] = ( |
695 | 706 | data["tx_pos_mm"][snapshot_idxs].unsqueeze(0) / self.distance_normalization |
696 | 707 | ) |
697 | | - |
| 708 | + breakpoint() |
698 | 709 | segmentation = segment_session( |
699 | 710 | data["signal_matrix"][0][0].numpy(), |
700 | 711 | gpu=self.gpu, |
|
0 commit comments