Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Dec 15, 2023
1 parent 590e743 commit a8952bc
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions src/packse/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ def start_server(
storage_context = (
nullcontext(storage_path)
if storage_path is not None
else TemporaryDirectory(prefix="packse-serve-")
else (
get_storage_directory()
if background
else TemporaryDirectory(prefix="packse-serve-")
)
)
with storage_context as storage_path:
# Ensure we have the right type, tmpdir returns a string
Expand All @@ -72,7 +76,7 @@ def start_server(
logger.debug("Storing data at %s", storage_path)

logger.info("Initializing server...")
subprocess.check_output(
subprocess.call(
["devpi-init", "--serverdir", str(server_storage)], stderr=subprocess.STDOUT
)

Expand All @@ -91,25 +95,30 @@ def start_server(
"--port",
str(port),
],
# creationflags=(
# subprocess.DETACHED_PROCESS | subprocess.CREATE_NEW_PROCESS_GROUP
# ),
stderr=subprocess.STDOUT,
stdout=subprocess.PIPE,
stdout=open(Path.cwd() / "output.txt", "wb"),
# close_fds=True,
)

# TODO(zanieb): Factor this into a utility
try:
line = ""
while "Serving on" not in line:
line = server_process.stdout.readline().decode()
if logger.getEffectiveLevel() <= logging.DEBUG:
print(line, end="")
if "Address already in use" in line:
raise ServeAddressInUse(server_url)
# line = ""
# while "Serving on" not in line:
# line = server_process.stdout.readline().decode()
# if logger.getEffectiveLevel() <= logging.DEBUG:
# print(line, end="")
# if "Address already in use" in line:
# raise ServeAddressInUse(server_url)
time.sleep(5)

# Server started!
write_server_pid(server_process.pid)

logger.info("Configuring client...")
subprocess.check_output(
subprocess.call(
["devpi", "use", "--clientdir", str(client_storage), server_url],
stderr=subprocess.STDOUT,
)
Expand Down Expand Up @@ -168,6 +177,10 @@ def start_server(
logger.info("Ready!")

if background:
# server_process.stdout.close()
# server_process.stderr.close()
# server_process.stdin.close()

logger.info("Running in background with PID %s", server_process.pid)
logger.info("Stop server with `packse server stop`.")
print(index_url)
Expand Down

0 comments on commit a8952bc

Please sign in to comment.