FinceptTerminal is a modern finance application offering advanced market analytics, investment research, and economic data tools, designed for interactive exploration and data-driven decision-making in a user-friendly environment.
C++ ai-agentsalgorithmic-tradingbloomberg-terminalcppfinancefinancial-marketsfintechgood-first-issueinvestmentinvestment-researchmachine-learningopensourcepythonqtquantitative-financestock-markettrading
Fix PythonWorker cold start drop issue
Abhi Kakadiya38e1202cd396
diff --git a/fincept-qt/src/python/PythonRunner.cpp b/fincept-qt/src/python/PythonRunner.cppindex 79c0ae96c..f9075dcaf 100644--- a/fincept-qt/src/python/PythonRunner.cpp+++ b/fincept-qt/src/python/PythonRunner.cpp@@ -239,6 +239,9 @@ void PythonRunner::find_python_async() {LOG_WARN("Python", "No Python interpreter found");}python_init_done_ = true;+ if (!python_path_.isEmpty()) {+ emit python_ready();+ }// Drain any requests that were queued while we were detectingstart_next();@@ -299,12 +302,55 @@ QString PythonRunner::find_scripts_dir() const {// ── Run Script ───────────────────────────────────────────────────────────────+bool PythonRunner::route_yfinance_to_daemon(const QStringList& args, Callback cb) {+ if (!is_available()) return false;++ if (args.isEmpty()) return false;+ const QString action = args[0];+ QJsonObject payload;++ if (action == "quote" || action == "info" || action == "news" || action == "financials" || action == "company_profile") {+ if (args.size() > 1) payload["symbol"] = args[1];+ if (action == "news" && args.size() > 2) payload["count"] = args[2].toInt();+ } else if (action == "batch_quotes" || action == "batch_sparklines" || action == "multiple_profiles" || action == "multiple_ratios") {+ QJsonArray syms;+ for (int i = 1; i < args.size(); ++i) syms.append(args[i]);+ payload["symbols"] = syms;+ } else if (action == "historical_period") {+ if (args.size() > 1) payload["symbol"] = args[1];+ if (args.size() > 2) payload["period"] = args[2];+ if (args.size() > 3) payload["interval"] = args[3];+ } else if (action == "search") {+ if (args.size() > 1) payload["query"] = args[1];+ } else {+ return false; // Action not supported or requires subprocess+ }++ PythonWorker::instance().submit(action, payload, [cb](bool ok, QJsonObject result, QString error) {+ PythonResult r;+ r.success = ok;+ r.error = error;+ if (ok) {+ r.output = QString::fromUtf8(QJsonDocument(result).toJson(QJsonDocument::Compact));+ }+ cb(r);+ });++ return true;+}+void PythonRunner::run(const QString& script, const QStringList& args, Callback cb, StreamCallback on_line) {if (python_init_done_ && python_path_.isEmpty()) {cb({false, {}, "Python not available — run first-time setup from the app", -1});return;}+ if (script == QLatin1String("yfinance_data.py")) {+ if (route_yfinance_to_daemon(args, cb))+ return;+ // falls through to normal subprocess queue below+ }+QString script_path = scripts_dir_ + "/" + script;if (!QFileInfo::exists(script_path)) {cb({false, {}, "Script not found: " + script_path, -1});diff --git a/fincept-qt/src/python/PythonRunner.h b/fincept-qt/src/python/PythonRunner.hindex 8d2c93fd5..bd9ff5377 100644--- a/fincept-qt/src/python/PythonRunner.h+++ b/fincept-qt/src/python/PythonRunner.h@@ -63,7 +63,11 @@ class PythonRunner : public QObject {/// Set max concurrent Python processes (default: 3)void set_max_concurrent(int n) { max_concurrent_ = n; }+ signals:+ void python_ready();+private:+ bool route_yfinance_to_daemon(const QStringList& args, Callback cb);PythonRunner();QString find_python_sync() const;void find_python_async();diff --git a/fincept-qt/src/python/PythonWorker.cpp b/fincept-qt/src/python/PythonWorker.cppindex 2c0299ac9..46e6a36b5 100644--- a/fincept-qt/src/python/PythonWorker.cpp+++ b/fincept-qt/src/python/PythonWorker.cpp@@ -46,6 +46,10 @@ PythonWorker::PythonWorker() {proc_->kill();}});++ connect(&PythonRunner::instance(), &PythonRunner::python_ready, this, [this]() {+ ensure_started();+ });}PythonWorker::~PythonWorker() {@@ -116,6 +120,7 @@ void PythonWorker::launch_process() {python_exe = runner.python_path();if (python_exe.isEmpty()) {LOG_WARN("PythonWorker", "No Python interpreter resolved — worker disabled");+ QTimer::singleShot(500, this, [this]() { ensure_started(); });return;}