Skip to content

Commit

Permalink
switch to blocking put with timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
t-sasatani committed Nov 1, 2024
1 parent 19f6b18 commit ac0a66d
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions miniscope_io/stream_daq.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def _uart_recv(
uart_bites = serial_port.read_until(pre_bytes)
log_uart_buffer = [x for x in uart_bites]
try:
serial_buffer_queue.put(log_uart_buffer, block=False)
serial_buffer_queue.put(log_uart_buffer, block=True, timeout=1)
except queue.Full:
self.logger.warning("Serial buffer queue full, skipping buffer.")
finally:
Expand Down Expand Up @@ -353,7 +353,7 @@ def _fpga_recv(
buf_stop + len(self.preamble),
)
try:
serial_buffer_queue.put(cur_buffer[buf_start:buf_stop].tobytes(), block=False)
serial_buffer_queue.put(cur_buffer[buf_start:buf_stop].tobytes(), block=True, timeout=1)
except queue.Full:
locallogs.warning("Serial buffer queue full, skipping buffer.")
if pre_pos:
Expand All @@ -362,7 +362,7 @@ def _fpga_recv(
finally:
locallogs.debug("Quitting, putting sentinel in queue")
try:
serial_buffer_queue.put(None, block=False)
serial_buffer_queue.put(None, block=True, timeout=1)
except queue.Full:
locallogs.error("Serial buffer queue full, Could not put sentinel.")

Expand Down Expand Up @@ -422,7 +422,7 @@ def _buffer_to_frame(
)
if header_list:
try:
frame_buffer_queue.put((None, header_list), block=False)
frame_buffer_queue.put((None, header_list), block=True, timeout=1)
except queue.Full:
locallogs.warning("Frame buffer queue full, skipping frame.")
continue
Expand All @@ -435,7 +435,7 @@ def _buffer_to_frame(

# push previous frame_buffer into frame_buffer queue
try:
frame_buffer_queue.put((frame_buffer, header_list), block=False)
frame_buffer_queue.put((frame_buffer, header_list), block=True, timeout=1)
except queue.Full:
locallogs.warning("Frame buffer queue full, skipping frame.")

Expand Down Expand Up @@ -464,12 +464,12 @@ def _buffer_to_frame(
break
finally:
try:
frame_buffer_queue.put((None, header_list), block=False) # get remaining buffers.
frame_buffer_queue.put((None, header_list), block=True, timeout=1) # get remaining buffers.
except queue.Full:
locallogs.warning("Frame buffer queue full, skipping frame.")

try:
frame_buffer_queue.put(None, block=False)
frame_buffer_queue.put(None, block=True, timeout=1)
locallogs.debug("Quitting, putting sentinel in queue")
except queue.Full:
locallogs.error("Frame buffer queue full, Could not put sentinel.")
Expand Down Expand Up @@ -508,7 +508,7 @@ def _format_frame(

if not frame_data or len(frame_data) == 0:
try:
imagearray.put((None, header_list), block=False)
imagearray.put((None, header_list), block=True, timeout=1)
except queue.Full:
locallogs.warning("Image array queue full, skipping frame.")
continue
Expand All @@ -533,15 +533,15 @@ def _format_frame(
(self.config.frame_width, self.config.frame_height), dtype=np.uint8
)
try:
imagearray.put((frame, header_list), block=False)
imagearray.put((frame, header_list), block=True, timeout=1)
except queue.Full:
locallogs.warning("Image array queue full, skipping frame.")
if continuous is False:
break
finally:
locallogs.debug("Quitting, putting sentinel in queue")
try:
imagearray.put(None, block=False)
imagearray.put(None, block=True, timeout=1)
except queue.Full:
locallogs.error("Image array queue full, Could not put sentinel.")

Expand Down

0 comments on commit ac0a66d

Please sign in to comment.