Code_TYMPAN  4.4.0
Industrial site acoustic simulation
Macros | Functions
subprocess_util.cpp File Reference

Utilitaires pour les interactions entre l'application tympan et des sous-processus python. More...

#include <QFile>
#include <QCoreApplication>
#include <QProcess>
#include <QDir>
#include <QRegularExpression>
#include <QEventLoop>
#include <QTimer>
#include <QElapsedTimer>
#include <atomic>
#include "Tympan/core/defines.h"
#include "Tympan/core/chrono.h"
#include "Tympan/core/logging.h"
#include "Tympan/core/exceptions.h"
#include "subprocess_util.h"
Include dependency graph for subprocess_util.cpp:

Go to the source code of this file.

Macros

#define TYMPAN_REL_CYTHON_PATH   "cython"
 
#define COMPUTATION_TIMEOUT   10000
 

Functions

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...
 
QStringList _python_qprocess_environment ()
 
QString _get_python_interp ()
 
std::string _read_environment_variables (QStringList env)
 
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)
 Create and initialize a QTemporaryFile according to the current policy. More...
 
bool python (QStringList args, std::string &error_msg)
 Launch a Python subprocess and wait for it using a non-blocking UI loop. More...
 

Detailed Description

Utilitaires pour les interactions entre l'application tympan et des sous-processus python.

Definition in file subprocess_util.cpp.

Macro Definition Documentation

◆ COMPUTATION_TIMEOUT

#define COMPUTATION_TIMEOUT   10000

Definition at line 44 of file subprocess_util.cpp.

◆ TYMPAN_REL_CYTHON_PATH

#define TYMPAN_REL_CYTHON_PATH   "cython"

Definition at line 41 of file subprocess_util.cpp.

Function Documentation

◆ _get_python_interp()

QString _get_python_interp ( )

Definition at line 128 of file subprocess_util.cpp.

◆ _python_qprocess_environment()

QStringList _python_qprocess_environment ( )

Definition at line 76 of file subprocess_util.cpp.

◆ _read_environment_variables()

std::string _read_environment_variables ( QStringList  env)

Definition at line 149 of file subprocess_util.cpp.

◆ 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.