mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 08:24:53 +01:00
added option to run detached process
This commit is contained in:
parent
867dae4c6a
commit
f67002961a
2 changed files with 64 additions and 25 deletions
|
|
@ -62,6 +62,7 @@ from .execute import (
|
||||||
run_subprocess,
|
run_subprocess,
|
||||||
run_detached_process,
|
run_detached_process,
|
||||||
run_ayon_launcher_process,
|
run_ayon_launcher_process,
|
||||||
|
run_detached_ayon_launcher_process,
|
||||||
path_to_subprocess_arg,
|
path_to_subprocess_arg,
|
||||||
CREATE_NO_WINDOW
|
CREATE_NO_WINDOW
|
||||||
)
|
)
|
||||||
|
|
@ -162,6 +163,7 @@ __all__ = [
|
||||||
"run_subprocess",
|
"run_subprocess",
|
||||||
"run_detached_process",
|
"run_detached_process",
|
||||||
"run_ayon_launcher_process",
|
"run_ayon_launcher_process",
|
||||||
|
"run_detached_ayon_launcher_process",
|
||||||
"path_to_subprocess_arg",
|
"path_to_subprocess_arg",
|
||||||
"CREATE_NO_WINDOW",
|
"CREATE_NO_WINDOW",
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -201,29 +201,7 @@ def clean_envs_for_ayon_process(env=None):
|
||||||
return env
|
return env
|
||||||
|
|
||||||
|
|
||||||
def run_ayon_launcher_process(*args, add_sys_paths=False, **kwargs):
|
def _prepare_ayon_launcher_env(add_sys_paths: bool, kwargs):
|
||||||
"""Execute AYON process with passed arguments and wait.
|
|
||||||
|
|
||||||
Wrapper for 'run_process' which prepends AYON executable arguments
|
|
||||||
before passed arguments and define environments if are not passed.
|
|
||||||
|
|
||||||
Values from 'os.environ' are used for environments if are not passed.
|
|
||||||
They are cleaned using 'clean_envs_for_ayon_process' function.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
```
|
|
||||||
run_ayon_process("run", "<path to .py script>")
|
|
||||||
```
|
|
||||||
|
|
||||||
Args:
|
|
||||||
*args (str): ayon-launcher cli arguments.
|
|
||||||
**kwargs (Any): Keyword arguments for subprocess.Popen.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
str: Full output of subprocess concatenated stdout and stderr.
|
|
||||||
|
|
||||||
"""
|
|
||||||
args = get_ayon_launcher_args(*args)
|
|
||||||
env = kwargs.pop("env", None)
|
env = kwargs.pop("env", None)
|
||||||
# Keep env untouched if are passed and not empty
|
# Keep env untouched if are passed and not empty
|
||||||
if not env:
|
if not env:
|
||||||
|
|
@ -239,8 +217,7 @@ def run_ayon_launcher_process(*args, add_sys_paths=False, **kwargs):
|
||||||
new_pythonpath.append(path)
|
new_pythonpath.append(path)
|
||||||
lookup_set.add(path)
|
lookup_set.add(path)
|
||||||
env["PYTHONPATH"] = os.pathsep.join(new_pythonpath)
|
env["PYTHONPATH"] = os.pathsep.join(new_pythonpath)
|
||||||
|
return env
|
||||||
return run_subprocess(args, env=env, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
def run_detached_process(args, **kwargs):
|
def run_detached_process(args, **kwargs):
|
||||||
|
|
@ -314,6 +291,66 @@ def run_detached_process(args, **kwargs):
|
||||||
return process
|
return process
|
||||||
|
|
||||||
|
|
||||||
|
def run_ayon_launcher_process(
|
||||||
|
*args, add_sys_paths=False, **kwargs
|
||||||
|
):
|
||||||
|
"""Execute AYON process with passed arguments and wait.
|
||||||
|
|
||||||
|
Wrapper for 'run_process' which prepends AYON executable arguments
|
||||||
|
before passed arguments and define environments if are not passed.
|
||||||
|
|
||||||
|
Values from 'os.environ' are used for environments if are not passed.
|
||||||
|
They are cleaned using 'clean_envs_for_ayon_process' function.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```
|
||||||
|
run_ayon_process("run", "<path to .py script>")
|
||||||
|
```
|
||||||
|
|
||||||
|
Args:
|
||||||
|
*args (str): ayon-launcher cli arguments.
|
||||||
|
add_sys_paths (bool): Add system paths to PYTHONPATH.
|
||||||
|
**kwargs (Any): Keyword arguments for subprocess.Popen.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: Full output of subprocess concatenated stdout and stderr.
|
||||||
|
|
||||||
|
"""
|
||||||
|
args = get_ayon_launcher_args(*args)
|
||||||
|
env = _prepare_ayon_launcher_env(add_sys_paths, kwargs)
|
||||||
|
return run_subprocess(args, env=env, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def run_detached_ayon_launcher_process(
|
||||||
|
*args, add_sys_paths=False, **kwargs
|
||||||
|
):
|
||||||
|
"""Execute AYON process with passed arguments and wait.
|
||||||
|
|
||||||
|
Wrapper for 'run_process' which prepends AYON executable arguments
|
||||||
|
before passed arguments and define environments if are not passed.
|
||||||
|
|
||||||
|
Values from 'os.environ' are used for environments if are not passed.
|
||||||
|
They are cleaned using 'clean_envs_for_ayon_process' function.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
```
|
||||||
|
run_ayon_process("run", "<path to .py script>")
|
||||||
|
```
|
||||||
|
|
||||||
|
Args:
|
||||||
|
*args (str): ayon-launcher cli arguments.
|
||||||
|
add_sys_paths (bool): Add system paths to PYTHONPATH.
|
||||||
|
**kwargs (Any): Keyword arguments for subprocess.Popen.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: Full output of subprocess concatenated stdout and stderr.
|
||||||
|
|
||||||
|
"""
|
||||||
|
args = get_ayon_launcher_args(*args)
|
||||||
|
env = _prepare_ayon_launcher_env(add_sys_paths, kwargs)
|
||||||
|
return run_detached_process(args, env=env, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def path_to_subprocess_arg(path):
|
def path_to_subprocess_arg(path):
|
||||||
"""Prepare path for subprocess arguments.
|
"""Prepare path for subprocess arguments.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue