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

feat: Add a hidden way to access Fluent's stdout/stderr #3504

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions src/ansys/fluent/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,11 @@ def version_info() -> str:

# Whether to clear environment variables related to Fluent parallel mode
CLEAR_FLUENT_PARA_ENVS = False

# Set stdout of the launched Fluent process
# Valid values are same as subprocess.Popen's stdout argument
LAUNCH_FLUENT_STDOUT = None

# Set stderr of the launched Fluent process
# Valid values are same as subprocess.Popen's stderr argument
LAUNCH_FLUENT_STDERR = None
4 changes: 4 additions & 0 deletions src/ansys/fluent/core/launcher/launcher_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def _get_subprocess_kwargs_for_fluent(env: Dict[str, Any], argvals) -> Dict[str,
kwargs: Dict[str, Any] = {}
if is_slurm:
kwargs.update(stdout=subprocess.PIPE)
else:
kwargs.update(
stdout=pyfluent.LAUNCH_FLUENT_STDOUT, stderr=pyfluent.LAUNCH_FLUENT_STDERR
)
if is_windows():
kwargs.update(shell=True, creationflags=subprocess.CREATE_NEW_PROCESS_GROUP)
else:
Expand Down
11 changes: 8 additions & 3 deletions src/ansys/fluent/core/launcher/standalone_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ def __init__(
The allocated machines and core counts are queried from the scheduler environment and
passed to Fluent.
"""
import ansys.fluent.core as pyfluent

self.argvals, self.new_session = _get_argvals_and_session(locals().copy())
self.file_transfer_service = file_transfer_service
if os.getenv("PYFLUENT_SHOW_SERVER_GUI") == "1":
Expand Down Expand Up @@ -214,7 +216,9 @@ def __init__(
self.argvals["topy"], self.argvals["journal_file_names"]
)

if is_windows():
if is_windows() and not (
pyfluent.LAUNCH_FLUENT_STDOUT or pyfluent.LAUNCH_FLUENT_STDERR
):
# Using 'start.exe' is better; otherwise Fluent is more susceptible to bad termination attempts.
self._launch_cmd = 'start "" ' + self._launch_string
else:
Expand All @@ -231,7 +235,7 @@ def __call__(self):
try:
logger.debug(f"Launching Fluent with command: {self._launch_cmd}")

subprocess.Popen(self._launch_cmd, **self._kwargs)
process = subprocess.Popen(self._launch_cmd, **self._kwargs)

try:
_await_fluent_launch(
Expand All @@ -247,7 +251,7 @@ def __call__(self):
logger.warning(
f"Retrying Fluent launch with less robust command: {launch_cmd}"
)
subprocess.Popen(launch_cmd, **self._kwargs)
process = subprocess.Popen(launch_cmd, **self._kwargs)
_await_fluent_launch(
self._server_info_file_name,
self.argvals["start_timeout"],
Expand All @@ -264,6 +268,7 @@ def __call__(self):
launcher_args=self.argvals,
inside_container=False,
)
session._process = process
start_watchdog = _confirm_watchdog_start(
self.argvals["start_watchdog"],
self.argvals["cleanup_on_exit"],
Expand Down