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

[Core] Add Process for Flushing Streams #12154

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

Conversation

matekelemen
Copy link
Contributor

Nearly every MainKratos.py I've ever seen begins by defining an AnalysisStage that flushes stdout regularly. In this PR, I'm adding a process that does the same thing to make the main python scripts cleaner.

Copy link
Member

@philbucher philbucher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would make this part of the analysis stage, see what I did in the CoSim Analysis Stage. I quite like the solution, it is simple yet worked well for me

Comment on lines +95 to +98
if self.__flush_stdout:
sys.stdout.flush()
if self.__flush_stderr:
sys.stderr.flush()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my experience also a lot of stuff gets stuck in the logger:

@staticmethod
def Flush():
sys.stdout.flush()
KM.Logger.Flush()

Copy link
Contributor Author

@matekelemen matekelemen Mar 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait, which stream is the logger using? I thought it was writing to stdout.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on how the Logger is constructed. It can use to have std::out, or std::fstream or other stream types as well. So using as @philbucher mentioned makes sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def AddFileLoggerOutput(log_file_name):
file_logger = Kratos.FileLoggerOutput(log_file_name)
default_severity = Kratos.Logger.GetDefaultOutput().GetSeverity()
Kratos.Logger.GetDefaultOutput().SetSeverity(Kratos.Logger.Severity.WARNING)
Kratos.Logger.AddOutput(file_logger)
return default_severity, file_logger
def RemoveFileLoggerOutput(default_severity, file_logger):
Kratos.Logger.Flush()
Kratos.Logger.RemoveOutput(file_logger)
Kratos.Logger.GetDefaultOutput().SetSeverity(default_severity)

@matekelemen
Copy link
Contributor Author

matekelemen commented Mar 6, 2024

I would make this part of the analysis stage, see what I did in the CoSim Analysis Stage. I quite like the solution, it is simple yet worked well for me

fine by me, it's a matter of whether the @KratosMultiphysics/technical-committee is ok with touching AnalysisStage.

@rubenzorrilla
Copy link
Member

I'd follow @philbucher 's suggestion as it keeps the "automatic" handling of the flush, which I find is more convenient for the user.

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

Successfully merging this pull request may close these issues.

4 participants