Skip to content

Commit

Permalink
new attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
tochilinak committed Nov 15, 2023
1 parent af207a4 commit 241d65a
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ class PythonSymbolicAnalysisRunnerImpl(
receiver: USVMPythonAnalysisResultReceiver,
isCancelled: () -> Boolean
) {
val start = System.currentTimeMillis()
val processBuilder = setupEnvironment(runConfig)
val process = processBuilder.start()
val readingThread = ReadingThread(serverSocketChannel, receiver, isCancelled)
val waitingThread = WaitingThread(process, runConfig, readingThread, isCancelled)
val newIsCancelled = {
isCancelled() || System.currentTimeMillis() - start < runConfig.timeoutMs
}
val readingThread = ReadingThread(serverSocketChannel, receiver, newIsCancelled)
val waitingThread = WaitingThread(process, readingThread, newIsCancelled)
try {
readingThread.start()
waitingThread.start()
Expand Down Expand Up @@ -68,18 +72,15 @@ class PythonSymbolicAnalysisRunnerImpl(

class WaitingThread(
private val process: Process,
private val runConfig: USVMPythonRunConfig,
private val readingThread: Thread,
private val isCancelled: () -> Boolean
): Thread() {
override fun run() {
val start = System.currentTimeMillis()
while (System.currentTimeMillis() - start < runConfig.timeoutMs && readingThread.isAlive && process.isAlive && !isCancelled()) {
while (readingThread.isAlive && process.isAlive && !isCancelled()) {
sleep(10)
}
while (readingThread.isAlive) {
readingThread.interrupt()
}
readingThread.interrupt()
}
}

Expand Down

0 comments on commit 241d65a

Please sign in to comment.