Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inspect progress bars with a global handler #695

Merged
merged 15 commits into from
May 30, 2024
Merged
Changes from 2 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
21 changes: 8 additions & 13 deletions pyflask/manageNeuroconv/manage_neuroconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
from pathlib import Path
from typing import Any, Dict, List, Optional

from sse import MessageAnnouncer
from sse import format_sse
from .info import GUIDE_ROOT_FOLDER, STUB_SAVE_FOLDER_PATH, CONVERSION_SAVE_FOLDER_PATH

announcer = MessageAnnouncer()
from tqdm_publisher import TQDMProgressHandler

progress_handler = TQDMProgressHandler()

EXCLUDED_RECORDING_INTERFACE_PROPERTIES = ["contact_vector", "contact_shapes", "group", "location"]
EXTRA_RECORDING_INTERFACE_PROPERTIES = {
Expand Down Expand Up @@ -547,9 +549,6 @@ def convert_to_nwb(info: dict) -> str:

converter = instantiate_custom_converter(resolved_source_data, info["interfaces"])

def update_conversion_progress(**kwargs):
announcer.announce(dict(**kwargs, nwbfile_path=nwbfile_path), "conversion_progress")

# Assume all interfaces have the same conversion options for now
available_options = converter.get_conversion_options_schema()
options = (
Expand Down Expand Up @@ -685,10 +684,10 @@ def upload_project_to_dandi(

# Create an events endpoint
def listen_to_neuroconv_events():
messages = announcer.listen() # returns a queue.Queue
messages = progress_handler.listen() # returns a queue.Queue
while True:
CodyCBakerPhD marked this conversation as resolved.
Show resolved Hide resolved
msg = messages.get() # blocks until a new message arrives
yield msg
yield format_sse(msg)


def generate_dataset(input_path: str, output_path: str):
Expand Down Expand Up @@ -765,18 +764,14 @@ def inspect_nwb_folder(payload):
from nwbinspector.nwbinspector import InspectorOutputJSONEncoder
from pickle import PicklingError

from tqdm_publisher import TQDMProgressSubscriber

request_id = payload.get("request_id")
if request_id:
payload.pop("request_id")

kwargs = dict(
n_jobs=-2, # uses number of CPU - 1
progress_bar_class=TQDMProgressSubscriber,
progress_bar_options=dict(
on_progress_update=lambda message: announcer.announce(dict(request_id=request_id, **message))
),
progress_bar_class=progress_handler.create,
progress_bar_options=dict(additional_metadata=dict(request_id=request_id)),
ignore=[
"check_description",
"check_data_orientation",
Expand Down
Loading