Skip to content

Commit

Permalink
try
Browse files Browse the repository at this point in the history
  • Loading branch information
amh4r committed Oct 15, 2024
1 parent af29362 commit 7b7a56f
Showing 1 changed file with 8 additions and 25 deletions.
33 changes: 8 additions & 25 deletions inngest/experimental/dev_server/dev_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import typing

import httpx
import psutil


class _Server:
Expand All @@ -17,7 +16,7 @@ def origin(self) -> str:

def __init__(self) -> None:
self._enabled = os.getenv("DEV_SERVER_ENABLED") != "0"
self._output_thread: typing.Optional[threading.Thread] = None
# self._output_thread: typing.Optional[threading.Thread] = None

port: int
dev_server_port_env_var = os.getenv("DEV_SERVER_PORT")
Expand Down Expand Up @@ -51,15 +50,15 @@ def start(self) -> None:
f"{self.port}",
],
bufsize=1,
stderr=subprocess.STDOUT,
stdout=subprocess.PIPE,
# stderr=subprocess.STDOUT,
# stdout=subprocess.PIPE,
text=True,
universal_newlines=True,
)

self._ready_event.clear()
self._output_thread = threading.Thread(target=self._print_output)
self._output_thread.start()
# self._output_thread = threading.Thread(target=self._print_output)
# self._output_thread.start()
self._wait_for_server()

def _print_output(self) -> None:
Expand Down Expand Up @@ -91,8 +90,8 @@ def stop(self) -> None:

print("Dev Server: stopping")

if self._output_thread is None:
raise Exception("missing output thread")
# if self._output_thread is None:
# raise Exception("missing output thread")
if self._process is None:
raise Exception("missing process")

Expand All @@ -105,25 +104,9 @@ def stop(self) -> None:
self._process.kill()
self._process.wait(timeout=5)

self._output_thread.join()
self._kill_child_processes()
# self._output_thread.join()

print("Dev Server: stopped")

def _kill_child_processes(self) -> None:
if self._process is None:
raise Exception("missing process")

try:
parent = psutil.Process(self._process.pid)
children = parent.children(recursive=True)
for child in children:
child.terminate()
_, alive = psutil.wait_procs(children, timeout=5)
for p in alive:
p.kill()
except psutil.NoSuchProcess:
pass


server = _Server()

0 comments on commit 7b7a56f

Please sign in to comment.