MCPcopy Create free account
hub / github.com/Codeya-IDE/deepin-ide / initialize

Method initialize

src/tools/debugadapter/debugger/python/pythondebugger.cpp:110–148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108}
109
110void PythonDebugger::initialize(const QString &pythonExecute,
111 const QString &fileName,
112 const QString &projectCachePath)
113{
114 int startPort = 7000;
115 auto checkPortFree = [](int port) {
116 QProcess process;
117 QString cmd = QString("fuser %1/tcp").arg(port);
118 process.start(cmd);
119 process.waitForFinished();
120 QString ret = process.readAll();
121 if (ret.isEmpty())
122 return true;
123 return false;
124 };
125
126 while (startPort) {
127 if (checkPortFree(startPort)) {
128 break;
129 }
130 startPort--;
131 }
132
133 d->port = startPort;
134 QString validPort = QString::number(d->port);
135 QString pid = QString::number(QApplication::applicationPid());
136 QString logFolder = projectCachePath + "/dap/pylog";
137 QString param = pythonExecute + " -m debugpy --listen " + validPort +
138 " --wait-for-client --log-to " + logFolder + " " + fileName + " --pid " + pid;
139
140 QStringList options;
141 options << "-c" << param;
142 auto env = d->process.processEnvironment();
143 env.insert("PYTHONPATH", packageInstallPath(pythonExecute));
144 d->process.setProcessEnvironment(env);
145 d->process.start("/bin/bash", options);
146 d->process.waitForStarted();
147 QThread::msleep(500); // The port may not start listening immediately when Python starts, resulting in the IDE being unable to connect. Wait for 500ms.
148}
149
150void PythonDebugger::slotReceiveClientInfo(const QString &ppid,
151 const QString &kit,

Callers

nothing calls this directly

Calls 9

numberClass · 0.85
msleepFunction · 0.85
readAllMethod · 0.80
insertMethod · 0.80
setProcessEnvironmentMethod · 0.80
packageInstallPathFunction · 0.70
QStringClass · 0.50
startMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected