Learn Environment
script_worker.hpp
Go to the documentation of this file.
1 #ifndef SCRIPT_WORKER_HPP
2 #define SCRIPT_WORKER_HPP
3 
4 #include <QObject>
5 #include <QString>
6 #include <QProcess>
7 #include <QList>
8 
10 
11 class ProcessRunner;
12 
21 class ScriptWorker : public QObject {
22  Q_OBJECT
23 
24 public:
33  ScriptWorker(const QString &notebookPath,
34  const QString &convertedScriptPath,
35  const QString &evalScriptPath,
36  bool parallelizedEvaluation,
37  int timeoutSeconds);
38 
39 public Q_SLOTS:
43  void startExecution();
44 
48  void forceStop();
49 
53  void executePythonScript(const QString &scriptPath, const QString &name);
54 
55 Q_SIGNALS:
59  void finished();
60 
65  void failed(const QString &error);
66 
67 private:
71  void convertAndExecuteNotebook();
72 
76  void executeConvertedScript();
77 
81  void evaluateScriptInParallel();
82 
86  void checkResult();
87 
91  void checkAndEmitFinished();
92 
98  QString formatMessage(const QString &msg, bool fromEval = false);
99 
100  QString notebookPath;
101  QString convertedScriptPath;
102  QString evalScriptPath;
103  bool parallelizedEvaluationRequired;
104  int timeoutSeconds;
105 
106  bool mainScriptFinished;
107  bool evalScriptFinished;
108 
109  QList<ProcessRunner*> processRunners;
110 
111  QString errorOutput;
112  QString evaluationOutput;
113 };
114 
115 #endif // SCRIPT_WORKER_HPP
NotebookConverter
A class for converting Jupyter notebooks to Python scripts and processing task pools.
Definition: notebook_converter.hpp:23
ProcessRunner::forceStop
void forceStop()
Forces the stop of the running process.
Definition: process_runner.cpp:35
QObject
ScriptWorker::finished
void finished()
Signal emitted when the script execution finishes.
ProcessRunner::errorReady
void errorReady(const QString &error)
Signal emitted when the process produces an error.
ScriptWorker::executePythonScript
void executePythonScript(const QString &scriptPath, const QString &name)
Executes a given Python script.
Definition: script_worker.cpp:172
ScriptWorker::ScriptWorker
ScriptWorker(const QString &notebookPath, const QString &convertedScriptPath, const QString &evalScriptPath, bool parallelizedEvaluation, int timeoutSeconds)
Constructs a ScriptWorker object.
Definition: script_worker.cpp:25
ScriptWorker::failed
void failed(const QString &error)
Signal emitted when the script execution fails.
ProcessRunner::start
void start()
Starts the execution of the process.
Definition: process_runner.cpp:25
ProcessRunner
Manages the execution of an external process with a timeout.
Definition: process_runner.hpp:15
ProcessRunner::outputReady
void outputReady(const QString &output)
Signal emitted when the process produces output.
notebook_converter.hpp
process_runner.hpp
ScriptWorker::forceStop
void forceStop()
Forces the stop of all running scripts.
Definition: script_worker.cpp:206
NotebookConverter::convertNotebook
bool convertNotebook(const QString &notebookPath)
Converts a Jupyter notebook to a Python script. Ignoring code cells with "solution" tag.
Definition: notebook_converter.cpp:29
ProcessRunner::finished
void finished(int exitCode, QProcess::ExitStatus exitStatus)
Signal emitted when the process finishes.
script_worker.hpp
ProcessRunner::timeout
void timeout()
Signal emitted when the process times out.
ScriptWorker::startExecution
void startExecution()
Starts the execution of the scripts.
Definition: script_worker.cpp:38
ScriptWorker
Manages the execution of scripts for tasks.
Definition: script_worker.hpp:21