Showing the changes to assignment-client/src/AssignmentClientMonitor.cpp (1 of 62 files). Show all
Unified · Split
| @@ -70,6 +70,17 @@ AssignmentClientMonitor::~AssignmentClientMonitor() { · 69 unmodified lines | |||
| 70 | stopChildProcesses(); | 70 | stopChildProcesses(); |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | void AssignmentClientMonitor::waitOnChildren(int msecs) { | ||
| 74 | QMutableListIterator<QProcess*> i(_childProcesses); | ||
| 75 | while (i.hasNext()) { | ||
| 76 | QProcess* childProcess = i.next(); | ||
| 77 | bool finished = childProcess->waitForFinished(msecs); | ||
| 78 | if (finished) { | ||
| 79 | i.remove(); | ||
| 80 | } | ||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 73 | void AssignmentClientMonitor::stopChildProcesses() { | 84 | void AssignmentClientMonitor::stopChildProcesses() { |
| 74 | auto nodeList = DependencyManager::get<NodeList>(); | 85 | auto nodeList = DependencyManager::get<NodeList>(); |
| 75 | 86 | ||
| @@ -79,11 +90,22 @@ void AssignmentClientMonitor::stopChildProcesses() { · 3 unmodified lines | |||
| 79 | QByteArray diePacket = byteArrayWithPopulatedHeader(PacketTypeStopNode); | 90 | QByteArray diePacket = byteArrayWithPopulatedHeader(PacketTypeStopNode); |
| 80 | nodeList->writeUnverifiedDatagram(diePacket, *node->getActiveSocket()); | 91 | nodeList->writeUnverifiedDatagram(diePacket, *node->getActiveSocket()); |
| 81 | }); | 92 | }); |
| 93 | |||
| 94 | // try to give all the children time to shutdown | ||
| 95 | waitOnChildren(15000); | ||
| 96 | } | ||
| 97 | |||
| 98 | void AssignmentClientMonitor::aboutToQuit() { | ||
| 99 | stopChildProcesses(); | ||
| 100 | // clear the log handler so that Qt doesn't call the destructor on LogHandler | ||
| 101 | qInstallMessageHandler(0); | ||
| 82 | } | 102 | } |
| 83 | 103 | ||
| 84 | void AssignmentClientMonitor::spawnChildClient() { | 104 | void AssignmentClientMonitor::spawnChildClient() { |
| 85 | QProcess *assignmentClient = new QProcess(this); | 105 | QProcess *assignmentClient = new QProcess(this); |
| 86 | 106 | ||
| 107 | _childProcesses.append(assignmentClient); | ||
| 108 | |||
| 87 | // unparse the parts of the command-line that the child cares about | 109 | // unparse the parts of the command-line that the child cares about |
| 88 | QStringList _childArguments; | 110 | QStringList _childArguments; |
| 89 | if (_assignmentPool != "") { | 111 | if (_assignmentPool != "") { |
| @@ -120,8 +142,6 @@ void AssignmentClientMonitor::spawnChildClient() { · 30 unmodified lines | |||
| 120 | qDebug() << "Spawned a child client with PID" << assignmentClient->pid(); | 142 | qDebug() << "Spawned a child client with PID" << assignmentClient->pid(); |
| 121 | } | 143 | } |
| 122 | 144 | ||
| 123 | |||
| 124 | |||
| 125 | void AssignmentClientMonitor::checkSpares() { | 145 | void AssignmentClientMonitor::checkSpares() { |
| 126 | auto nodeList = DependencyManager::get<NodeList>(); | 146 | auto nodeList = DependencyManager::get<NodeList>(); |
| 127 | QUuid aSpareId = ""; | 147 | QUuid aSpareId = ""; |
| @@ -157,6 +177,8 @@ void AssignmentClientMonitor::checkSpares() { · 29 unmodified lines | |||
| 157 | nodeList->writeUnverifiedDatagram(diePacket, childNode); | 177 | nodeList->writeUnverifiedDatagram(diePacket, childNode); |
| 158 | } | 178 | } |
| 159 | } | 179 | } |
| 180 | |||
| 181 | waitOnChildren(0); | ||
| 160 | } | 182 | } |
| 161 | 183 | ||
| 162 | 184 | ||