Skip to content
Open
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
13 changes: 7 additions & 6 deletions pyopia/realtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import pathlib
import queue
from collections import deque
import threading
import time

Expand Down Expand Up @@ -46,7 +47,7 @@ def _enqueue_file_if_new(
return False
seen_files.add(file_key)

file_queue.put(file_path)
file_queue.append(file_path)
return True


Expand Down Expand Up @@ -103,8 +104,9 @@ def _worker_loop(
):
while not stop_event.is_set():
try:
filepath = file_queue.get(timeout=1)
except queue.Empty:
filepath = file_queue.pop()
except IndexError:
time.sleep(0.1)
continue

try:
Expand All @@ -123,7 +125,7 @@ def _worker_loop(
finally:
with state_lock:
runtime_state["current_file"] = "idle"
file_queue.task_done()
time.sleep(0.1)


def run_realtime(pipeline_config: dict, watch_folder: str | None = None):
Expand All @@ -145,7 +147,7 @@ def run_realtime(pipeline_config: dict, watch_folder: str | None = None):

processing_pipeline = pyopia.pipeline.Pipeline(pipeline_config)

file_queue = queue.Queue()
file_queue = deque(maxlen=10)
stop_event = threading.Event()
seen_files: set[str] = set()
seen_lock = threading.Lock()
Expand Down Expand Up @@ -212,7 +214,6 @@ def run_realtime(pipeline_config: dict, watch_folder: str | None = None):
description=(
"[blue]Realtime active"
f" | processed: {processed_count}"
f" | queued: {file_queue.qsize()}"
f" | current: {current_file}"
),
)
Expand Down
Loading