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

fix: Make file upload work when waved run separately #2225 #2232

Merged
merged 8 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
27 changes: 19 additions & 8 deletions py/h2o_wave/h2o_wave/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import click
import httpx
import inquirer
import psutil
import uvicorn
from click import Choice, option
from h2o_wave.share import listen_on_socket
Expand Down Expand Up @@ -143,40 +144,50 @@ def run(app: str, no_reload: bool, no_autostart: bool):

# Try to start Wave daemon if not running or turned off.
server_port = int(os.environ.get('H2O_WAVE_LISTEN', ':10101').split(':')[-1])
server_not_running = _scan_free_port(server_port) == server_port
server_running = _scan_free_port(server_port) != server_port

waved_process = None
if no_autostart:
autostart = False
else:
autostart = os.environ.get('H2O_WAVE_NO_AUTOSTART', 'false').lower() in ['false', '0', 'f']

waved_path = os.path.join(sys.exec_prefix, 'waved.exe' if IS_WINDOWS else 'waved')
waved_cwd = sys.exec_prefix
proc_name = 'waved.exe' if IS_WINDOWS else 'waved'
# If waved is running, find its cwd.
if server_running:
for proc in psutil.process_iter():
if proc.name() == proc_name:
try:
waved_cwd = psutil.Process(proc.pid).cwd()
except psutil.NoSuchProcess:
pass
waved_path = os.path.join(waved_cwd, proc_name)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only true for platform specific wheel files. Platform-agnostic whl does not contain waved binary.

# OS agnostic wheels do not include waved - needed for HAC.
is_waved_present = os.path.isfile(waved_path)

try:
if autostart and is_waved_present and server_not_running:
if autostart and is_waved_present and not server_running:
kwargs = {}
if IS_WINDOWS:
kwargs['creationflags'] = subprocess.CREATE_NEW_PROCESS_GROUP

waved_process = subprocess.Popen([waved_path], cwd=sys.exec_prefix, env=os.environ.copy(), **kwargs)
time.sleep(1)
server_not_running = _scan_free_port(server_port) == server_port
server_running = _scan_free_port(server_port) != server_port
retries = 3
while retries > 0 and server_not_running:
while retries > 0 and not server_running:
print('Cannot connect to Wave server, retrying...')
time.sleep(2)
server_not_running = _scan_free_port(server_port) == server_port
server_running = _scan_free_port(server_port) != server_port
retries = retries - 1

if autostart and server_not_running:
if autostart and not server_running:
print('Could not connect to Wave server. Please start the Wave server (waved or waved.exe) prior to running any app.')
return

if not os.environ.get('H2O_WAVE_WAVED_DIR') and is_waved_present:
os.environ['H2O_WAVE_WAVED_DIR'] = sys.exec_prefix
os.environ['H2O_WAVE_WAVED_DIR'] = waved_cwd
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this works reliably, we can deprecate H2O_WAVE_WAVED_DIR. Add a TODO here for now.

reload_exclude = os.environ.get('H2O_WAVE_RELOAD_EXCLUDE', None)
if reload_exclude:
reload_exclude = reload_exclude.split(os.pathsep)
Expand Down
1 change: 1 addition & 0 deletions py/h2o_wave/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dependencies = [
"Click",
"inquirer",
"httpx>=0.16.1",
"psutil>=5.9.7",
marek-mihok marked this conversation as resolved.
Show resolved Hide resolved
"starlette>=0.13.8",
"uvicorn>=0.17.6",
]
Expand Down