-
Notifications
You must be signed in to change notification settings - Fork 67
Experimental: Track CLI processes using Process Manager #1540
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,9 +59,9 @@ def main_cli(ctx, *_args, **_kwargs): | |
| if os.getenv("AYON_HEADLESS_MODE") == "1": | ||
| print(ctx.get_help()) | ||
| sys.exit(0) | ||
| else: | ||
| ctx.params.pop("project") | ||
| ctx.forward(tray) | ||
|
|
||
| ctx.params.pop("project") | ||
| ctx.forward(tray) | ||
|
|
||
|
|
||
| @main_cli.command() | ||
|
|
@@ -386,6 +386,53 @@ def main(*args, **kwargs): | |
|
|
||
| _cleanup_project_args() | ||
|
|
||
| app_addon = addons_manager.get_enabled_addon("applications") | ||
|
Member
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. Do you realize that this cli is also used for small subprocesses like extract burnin, ffmpeg user service ocio functionality etc? Some of them are already outputing to parent process. On windows it also doesn't make sense to read output if stdout/stderr is not available at all (is set to I don't think we should do it automatically for all processes TBH. It should be explicit and not enabled by default. Have one function in ayon-core to store the process info that can be easily called.
Member
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. With that function we should move that logic to ayon-core. |
||
|
|
||
| import semver | ||
|
|
||
| app_addon_version = semver.Version.parse(app_addon.version).to_tuple() | ||
| # Process Manager API is available since 1.2.4 | ||
| if app_addon is not None and app_addon_version >= (1, 2, 4): | ||
| from ayon_applications.process import ProcessManager, ProcessInfo | ||
| import tempfile | ||
|
|
||
| process_info = ProcessInfo( | ||
| name="ayon-cli", | ||
| executable=Path(sys.executable), | ||
| args=list(sys.argv), | ||
| env=dict(os.environ), | ||
| pid=os.getpid(), | ||
| cwd=os.getcwd(), | ||
| ) | ||
|
|
||
| output_file = None | ||
| with tempfile.NamedTemporaryFile( | ||
| mode="w", prefix="ayon_ayon-cli_output_", | ||
| suffix=".txt", | ||
| delete=False, | ||
| encoding="utf-8") as temp_file: | ||
| output_file = temp_file.name | ||
|
|
||
| process_info.output = Path(output_file) | ||
|
|
||
| process_manager = ProcessManager() | ||
| process_manager.store_process_info(process_info) | ||
|
|
||
| with open(output_file, "a", encoding="utf-8") as f: | ||
| sys.stdout = sys.stderr = f | ||
|
|
||
| try: | ||
| main_cli( | ||
| prog_name="ayon", | ||
| obj={"addons_manager": addons_manager}, | ||
| args=(sys.argv[1:]), | ||
| ) | ||
| except Exception: # noqa | ||
| exc_info = sys.exc_info() | ||
| print("!!! AYON crashed:") | ||
| traceback.print_exception(*exc_info) | ||
| sys.exit(1) | ||
|
|
||
| try: | ||
| main_cli( | ||
| prog_name="ayon", | ||
|
|
||
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.
We should not start tray in headless mode.
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.
if I read this code right - the whole original chunk of code is:
you don't need else because of
sys.exit()?