Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Mar 14, 2024
1 parent fb38daa commit 3806458
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/tqdm_publisher/_demo/_client.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ header {
height: 100%;
background-color: #4caf50;
width: 0%;
}
}
9 changes: 4 additions & 5 deletions src/tqdm_publisher/_demo/_demo_command_line_interface.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import os
import subprocess
import sys
from pathlib import Path

import webbrowser
from pathlib import Path

DEMOS = {
"single": "_single",
Expand Down Expand Up @@ -44,15 +43,15 @@ def _command_line_interface():
# client_relative_path = Path(subpath) / "_client.py"
# subprocess.Popen(['python', str(DEMO_BASE_FOLDER_PATH / subpath / "_server.py")])
# subprocess.Popen(['python', str(DEMO_BASE_FOLDER_PATH / subpath / "_client.py")])

# else:

client_relative_path = Path(subpath) / "_client.html"
subprocess.Popen(['python', '-m', 'http.server', str(CLIENT_PORT), "-d", DEMO_BASE_FOLDER_PATH])
subprocess.Popen(["python", "-m", "http.server", str(CLIENT_PORT), "-d", DEMO_BASE_FOLDER_PATH])

webbrowser.open_new_tab(f"http://localhost:{CLIENT_PORT}/{client_relative_path}")

subprocess.run(['python', str(DEMO_BASE_FOLDER_PATH / subpath / "_server.py")])
subprocess.run(["python", str(DEMO_BASE_FOLDER_PATH / subpath / "_server.py")])

else:
print(f"{command} is an invalid command.")
5 changes: 2 additions & 3 deletions src/tqdm_publisher/_demo/_multiple/_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def run(self):
Defaults are chosen for a deterministic and regular update period of one second for a total time of one minute.
"""
all_task_durations_in_seconds = [.1 for _ in range(100)] # Ten seconds of one hundred tasks
all_task_durations_in_seconds = [0.1 for _ in range(100)] # Ten seconds of one hundred tasks
progress_bar = self.progress_bar = tqdm_publisher.TQDMPublisher(iterable=all_task_durations_in_seconds)
progress_bar.subscribe(callback=self.update)

Expand All @@ -44,7 +44,6 @@ def run(self):
# thread = threading.Thread(target=self.run_progress_bar)
# thread.start()


# Wait for messages from the client
async for message in websocket:
message_from_client = json.loads(message)
Expand All @@ -66,4 +65,4 @@ def run_demo() -> None:


if __name__ == "__main__":
run_demo()
run_demo()
14 changes: 7 additions & 7 deletions src/tqdm_publisher/_demo/_single_bar/_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def start_progress_bar(*, progress_callback: callable) -> None:
Defaults are chosen for a deterministic and regular update period of one second for a total time of one minute.
"""
all_task_durations_in_seconds = [.1 for _ in range(100)] # Ten seconds of one hundred tasks
all_task_durations_in_seconds = [0.1 for _ in range(100)] # Ten seconds of one hundred tasks
progress_bar = tqdm_publisher.TQDMPublisher(iterable=all_task_durations_in_seconds)

def run_function_on_progress_update(format_dict: dict) -> None:
Expand Down Expand Up @@ -44,9 +44,8 @@ def send_message_to_client(*, websocket: websockets.WebSocketServerProtocol, mes
This expects a WebSocket connection and a message (dict) to send.
"""

asyncio.run(
websocket.send(message=json.dumps(obj=message))
)
asyncio.run(websocket.send(message=json.dumps(obj=message)))


async def handler(websocket: websockets.WebSocketServerProtocol) -> None:
"""Handle messages from the client and manage the client connections."""
Expand All @@ -60,10 +59,11 @@ async def handler(websocket: websockets.WebSocketServerProtocol) -> None:
# Start the progress bar in a separate thread
thread = threading.Thread(
target=start_progress_bar,

# On each update of the progress bar, send this update to the requesting client
kwargs=dict(
progress_callback=lambda id, format_dict: send_message_to_client(websocket, dict(id=id, format_dict=format_dict))
progress_callback=lambda id, format_dict: send_message_to_client(
websocket, dict(id=id, format_dict=format_dict)
)
),
)
thread.start()
Expand All @@ -81,4 +81,4 @@ def run_demo() -> None:


if __name__ == "__main__":
run_demo()
run_demo()

0 comments on commit 3806458

Please sign in to comment.