-
Notifications
You must be signed in to change notification settings - Fork 326
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
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9868a66
chore: get waved dir path via temp file #2225
marek-mihok 5465edc
feat: find waved cwd by its process id #2225
marek-mihok 34c4672
chore: remove hatchling version lock #2225
marek-mihok c4384cd
fix: use sys.exec_prefix as a default waved path #2225
marek-mihok 6e55415
chore: set H2O_WAVE_WAVED_DIR only when waved is not running separate…
marek-mihok 9b18112
chore: remove unwanted negation #2225
marek-mihok bc5bcb4
chore: simplify #2225
marek-mihok c966d9b
chore: Refactor.
mturoci File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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) | ||
# 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this works reliably, we can deprecate |
||
reload_exclude = os.environ.get('H2O_WAVE_RELOAD_EXCLUDE', None) | ||
if reload_exclude: | ||
reload_exclude = reload_exclude.split(os.pathsep) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.