problem processing standardoutput
-
@jsulm
starting GPU monitor done
QObject::startTimer: Timers can only be used with threads started with QThread
bye bye now
QProcess: Destroyed while process ("nvidia-smi") is still running.
gpuProcessStarted
gpuProcessFinishedthis is the output its stops without printing any data
and i dont have a qt event loop
if u mean the start function this is it
gpuMonitorProcess.start("nvidia-smi --query-gpu=utilization.gpu,memory.used --format=csv -l 1");
its in the first code i added in the post@Dijkstra said in problem processing standardoutput:
and i dont have a qt event loop
Then how is this going to work? You need running Qt event loop if you want to use signals/slots.
"QObject::startTimer: Timers can only be used with threads started with QThread" - do you use multi threading?
And please show your current code with QTimer..."if u mean the start function this is it" - no, that is not what I mean. What I mean belongs to absolute Qt basics:
int main(int argc, char* argv[]) { QScopedPointer<QCoreApplication> app(createApplication(argc, argv)); if (qobject_cast<QApplication *>(app.data())) { // start GUI version... } else { // start non-GUI version... } return app->exec(); // This starts Qt event loop }
-
@Dijkstra said in problem processing standardoutput:
and i dont have a qt event loop
Then how is this going to work? You need running Qt event loop if you want to use signals/slots.
"QObject::startTimer: Timers can only be used with threads started with QThread" - do you use multi threading?
And please show your current code with QTimer..."if u mean the start function this is it" - no, that is not what I mean. What I mean belongs to absolute Qt basics:
int main(int argc, char* argv[]) { QScopedPointer<QCoreApplication> app(createApplication(argc, argv)); if (qobject_cast<QApplication *>(app.data())) { // start GUI version... } else { // start non-GUI version... } return app->exec(); // This starts Qt event loop }
if(argc <=1) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); } else { QString inputFileNameJSON = argv[1]; //; ApplicationEngine myApplicationEngine; //myApplicationEngine.checkAndStartServers(); myApplicationEngine.initPluginOutputListner(inputFileNameJSON); /*while(!myApplicationEngine.isProcessCompleted()) { QThread::msleep(100); }*/ myApplicationEngine.parseAccuracyCalculationParams(inputFileNameJSON); myApplicationEngine.ComputeAccuracy(); CPU_monitor cpu; //cpu.startCPU(true); myApplicationEngine.startGPUMonitor(true); /*for(int i=0;i<100;i++){ QThread::msleep(100); }*/ QTimer::singleShot(10000, [&myApplicationEngine](){ myApplicationEngine.stopGPUMonitor(true); }); //myApplicationEngine.stopGPUMonitor(true); //cpu.stopCPU(true); std::cout << "bye bye now" << std::endl; }
first condition starts the gui version and the other the non gui one and i am sorry for not knowing this basics w qt
-
if(argc <=1) { QApplication a(argc, argv); MainWindow w; w.show(); return a.exec(); } else { QString inputFileNameJSON = argv[1]; //; ApplicationEngine myApplicationEngine; //myApplicationEngine.checkAndStartServers(); myApplicationEngine.initPluginOutputListner(inputFileNameJSON); /*while(!myApplicationEngine.isProcessCompleted()) { QThread::msleep(100); }*/ myApplicationEngine.parseAccuracyCalculationParams(inputFileNameJSON); myApplicationEngine.ComputeAccuracy(); CPU_monitor cpu; //cpu.startCPU(true); myApplicationEngine.startGPUMonitor(true); /*for(int i=0;i<100;i++){ QThread::msleep(100); }*/ QTimer::singleShot(10000, [&myApplicationEngine](){ myApplicationEngine.stopGPUMonitor(true); }); //myApplicationEngine.stopGPUMonitor(true); //cpu.stopCPU(true); std::cout << "bye bye now" << std::endl; }
first condition starts the gui version and the other the non gui one and i am sorry for not knowing this basics w qt
@Dijkstra Simply start the event loop also in your second condition like you do in your first. Event loop is not a GUI thing - you can use it in console applications also (and you usually have to if you want to use, for example, signals/slots).
-
@Dijkstra Simply start the event loop also in your second condition like you do in your first. Event loop is not a GUI thing - you can use it in console applications also (and you usually have to if you want to use, for example, signals/slots).
-
@jsulm man thanks so much you are amazing it worked is their a way to stop it after it finishing as it doesnt reach the cout<<"bye bye now at the end "<<endl; as i also want to run the cpu and stop it at the same time of stoping the gpu
@Dijkstra said in problem processing standardoutput:
is their a way to stop it after it finishing
QTimer::singleShot(10000, [&myApplicationEngine](){ myApplicationEngine.stopGPUMonitor(true); qApp->exit() });
-
@Dijkstra said in problem processing standardoutput:
is their a way to stop it after it finishing
QTimer::singleShot(10000, [&myApplicationEngine](){ myApplicationEngine.stopGPUMonitor(true); qApp->exit() });
@jsulm sorry one last question this is what i did and it works just fine it just doesnt exit the process and keeps hanging in the terminal
QTimer::singleShot(10000, [&myApplicationEngine,&cpu](){ myApplicationEngine.stopGPUMonitor(true); cpu.stopCPU(true);qApp->exit(); std::cout << "bye bye now" << std::endl; qApp->exit(0); });
-
@jsulm sorry one last question this is what i did and it works just fine it just doesnt exit the process and keeps hanging in the terminal
QTimer::singleShot(10000, [&myApplicationEngine,&cpu](){ myApplicationEngine.stopGPUMonitor(true); cpu.stopCPU(true);qApp->exit(); std::cout << "bye bye now" << std::endl; qApp->exit(0); });
-
@Dijkstra Do you have any other loops somewhere?
Is it asking you to press a button to terminate?@jsulm
it doesnt ask for a button to terminate but there is a loop in the function that processes standard outputvoid ApplicationEngine::gpuProcessStandardOutput() { //std::cout << "gpuProcessStandardOutput" << std::endl; QTextStream rsyncStdoutStream(gpuMonitorProcess.readAllStandardOutput()); while (true) { QString line = rsyncStdoutStream.readLine(); if (line.isNull()) { g.finished=true; break; } else { QString utilization="",memory_used=""; //stream << line<<'\n'; //print to file for(int i=0;i<line.length();i++){ if(line[i]!=' ') utilization+=line[i]; else{ while(line[i]!='M'){ if(line[i].isDigit()) memory_used+=line[i]; i++; } break; } } //cout<<memory_used.toStdString()<<endl; g.gpu_utilization_memory_values.push_back(memory_used.toInt()); g.gpu_utilization_values.push_back(utilization.toInt()); if(!g.offline){ emit(sendgpuupdates(QString("%1").arg(line),"gpu utilization: ",QString("%1").arg(memory_used),"memory used")); } //std::cout<<line.toStdString()<<'\n'; if(utilization.length()!=15) std::cout<<"gpu utilization : "<<utilization.toStdString()<<std::endl; if(memory_used.length()) std::cout<<"memory used : "<<memory_used.toStdString()<<std::endl; } } }
-
@jsulm
it doesnt ask for a button to terminate but there is a loop in the function that processes standard outputvoid ApplicationEngine::gpuProcessStandardOutput() { //std::cout << "gpuProcessStandardOutput" << std::endl; QTextStream rsyncStdoutStream(gpuMonitorProcess.readAllStandardOutput()); while (true) { QString line = rsyncStdoutStream.readLine(); if (line.isNull()) { g.finished=true; break; } else { QString utilization="",memory_used=""; //stream << line<<'\n'; //print to file for(int i=0;i<line.length();i++){ if(line[i]!=' ') utilization+=line[i]; else{ while(line[i]!='M'){ if(line[i].isDigit()) memory_used+=line[i]; i++; } break; } } //cout<<memory_used.toStdString()<<endl; g.gpu_utilization_memory_values.push_back(memory_used.toInt()); g.gpu_utilization_values.push_back(utilization.toInt()); if(!g.offline){ emit(sendgpuupdates(QString("%1").arg(line),"gpu utilization: ",QString("%1").arg(memory_used),"memory used")); } //std::cout<<line.toStdString()<<'\n'; if(utilization.length()!=15) std::cout<<"gpu utilization : "<<utilization.toStdString()<<std::endl; if(memory_used.length()) std::cout<<"memory used : "<<memory_used.toStdString()<<std::endl; } } }
@Dijkstra said in problem processing standardoutput:
but there is a loo
Well, make sure you leave that loop
-
@Dijkstra said in problem processing standardoutput:
but there is a loo
Well, make sure you leave that loop