Skip to content

Commit

Permalink
Run server functions directly
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettmflynn committed Mar 14, 2024
1 parent c258d18 commit 8160b8a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
20 changes: 15 additions & 5 deletions src/tqdm_publisher/_demo/_demo_command_line_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@
import webbrowser
from pathlib import Path

from tqdm_publisher._demo._single_bar._server import run_single_bar_demo
from tqdm_publisher._demo._multiple._server import run_multiple_bar_demo


DEMOS = {
"single": "_single",
"multiple": "_multiple",
"single": dict(
subpath="_single_bar",
server=run_single_bar_demo
),
"multiple": dict(
subpath="_multiple",
server=run_multiple_bar_demo
)
# "parallel": "_parallel",
}

Expand Down Expand Up @@ -37,7 +47,7 @@ def _command_line_interface():

if command in DEMOS:

subpath = DEMOS[command]
demo_info = DEMOS[command]

# if command == "parallel":
# client_relative_path = Path(subpath) / "_client.py"
Expand All @@ -46,12 +56,12 @@ def _command_line_interface():

# else:

client_relative_path = Path(subpath) / "_client.html"
client_relative_path = Path(demo_info["subpath"]) / "_client.html"
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")])
demo_info["server"]()

else:
print(f"{command} is an invalid command.")
6 changes: 1 addition & 5 deletions src/tqdm_publisher/_demo/_multiple/_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,4 @@ async def spawn_server() -> None:

def run_multiple_bar_demo() -> None:
"""Trigger the execution of the asynchronous spawn."""
asyncio.run(spawn_server())


if __name__ == "__main__":
run_demo()
asyncio.run(spawn_server())

0 comments on commit 8160b8a

Please sign in to comment.