Code_TYMPAN  4.4.0
Industrial site acoustic simulation
Functions
subprocess_util.h File Reference

Utilities to interact with Python subprocesses from the Tympan application. More...

#include <QStringList>
#include <QTemporaryFile>
#include <string>
Include dependency graph for subprocess_util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool python (QStringList args, std::string &error_msg)
 Launch a Python subprocess and wait for it using a non-blocking UI loop. More...
 
bool must_keep_tmp_files ()
 Tell whether temporary files should be preserved (debug mode). More...
 
bool init_tmp_file (QTemporaryFile &tmp_file, bool keep_file=false)
 Create and initialize a QTemporaryFile according to the current policy. More...
 
void python_request_cancel ()
 Request cancellation of the currently running Python subprocess (UI hook, stage A). More...
 
bool python_cancel_was_requested ()
 Query whether a cancellation was requested since the last call to python(). More...
 

Detailed Description

Utilities to interact with Python subprocesses from the Tympan application.

Definition in file subprocess_util.h.

Function Documentation

◆ init_tmp_file()

bool init_tmp_file ( QTemporaryFile &  tmp_file,
bool  keep_file = false 
)

Create and initialize a QTemporaryFile according to the current policy.

The function ensures the file exists and is ready to be written to. Depending on keep_file and the global policy, the file may be configured to persist after the object is destroyed.

Parameters
tmp_fileReference to a QTemporaryFile object to initialize (not yet opened).
keep_fileIf true, prevents auto-removal on destruction (useful for debugging).
Returns
true on success (file created/opened), false otherwise.

Definition at line 200 of file subprocess_util.cpp.

Here is the caller graph for this function:

◆ must_keep_tmp_files()

bool must_keep_tmp_files ( )

Tell whether temporary files should be preserved (debug mode).

The policy (environment variables, build flags, etc.) is defined in the implementation. When this returns true, callers may avoid auto-removal of temporary artifacts for diagnostics.

Returns
true if temporary files must be kept, false otherwise.

Definition at line 185 of file subprocess_util.cpp.

Here is the caller graph for this function:

◆ python()

bool python ( QStringList  args,
std::string &  error_msg 
)

Launch a Python subprocess and wait for it using a non-blocking UI loop.

This function starts a Python interpreter with the given arguments and runs a local Qt event loop until the subprocess finishes (successfully or not). It is synchronous from the caller's perspective (returns when the process ends), but it does not block the GUI thread: the Qt event loop remains responsive.

Cancellation can be requested from the UI by calling python_request_cancel().

Parameters
argsArgument list passed to the Python interpreter (first item is the script path).
[out]error_msgOn failure, filled with a human-readable message in French intended for end users.
Returns
true if the subprocess exited normally with code 0, false otherwise.

Definition at line 213 of file subprocess_util.cpp.

Here is the caller graph for this function:

◆ python_cancel_was_requested()

bool python_cancel_was_requested ( )

Query whether a cancellation was requested since the last call to python().

Useful on the UI side to adapt user messaging (e.g., distinguishing a user-initiated interruption from an execution error).

Returns
true if a cancellation was requested, false otherwise.

Definition at line 54 of file subprocess_util.cpp.

◆ python_request_cancel()

void python_request_cancel ( )

Request cancellation of the currently running Python subprocess (UI hook, stage A).

Thread-safe with respect to the UI thread. The implementation attempts a graceful QProcess::terminate(), then issues QProcess::kill() after a short grace period if needed. Calling this when no subprocess is running is a no-op.

Definition at line 49 of file subprocess_util.cpp.