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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mkundu1
Copy link
Contributor

@mkundu1 mkundu1 commented Nov 22, 2024

Requested by @PyPablo

We cannot expose this as a full feature due to the limitations mentioned in #3436. Exposing a hidden way to access Fluent's stdout/stderr.

import subprocess
import ansys.fluent.core as pyfluent
pyfluent.LAUNCH_FLUENT_STDOUT = subprocess.PIPE
solver = pyfluent.launch_fluent()

for line in iter(solver._process.stdout.readline, b''):
    decoded_line = line.decode('utf-8')
    print(decoded_line, end='')
    if decoded_line.startswith("Cleanup script file"):  # Any other termination condition, e.g. break after 10 lines
        break

Note that, this doesn't work in ui_mode="gui" as mentioned in #3436.

@PyPablo
Copy link
Collaborator

PyPablo commented Nov 22, 2024

Hi @mkundu1 thanks a lot! If this something the user can access through a protected method in launch_fluent?
i.e.
session.__stdout

returns the str or whatever?

Also, is there any possibility to capture the return from the very beginning, i.e. what is printed out in the .trn file? Obviously one can read and parse the .trn file, but it is not as clean (and maybe not so obvious) than a built-in method

@mkundu1
Copy link
Contributor Author

mkundu1 commented Nov 22, 2024

Hi @mkundu1 thanks a lot! If this something the user can access through a protected method in launch_fluent? i.e. session.__stdout

returns the str or whatever?

Also, is there any possibility to capture the return from the very beginning, i.e. what is printed out in the .trn file? Obviously one can read and parse the .trn file, but it is not as clean (and maybe not so obvious) than a built-in method

@PyPablo Yes, the example code in the PR description above will print from the begining of the Fluent output till the line "Cleanup script file ..". The stdout is a buffer which will keep being populated as long as Fluent is running. The above code is a standard pattern to read from a buffer.

@hpohekar
Copy link
Collaborator

hpohekar commented Nov 24, 2024

@mkundu1 We can track the license error at least in non GUI mode now right ?

@seanpearsonuk

I think we can use asyncio for pausing and resuming subprocess stdout based on a flag in case of GUI mode. If "Unexpected license problem" is in output then we will show the error message accordingly otherwise we will pause the stdout in case of GUI mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants