Graceful shutdown of test calls this, then #verifyThreadsStopped
2845
@Override
    public void tellThreadsToStop() {
        super.tellThreadsToStop();
        for (DynamicThread thread : poolThreads) {
            stopThread(thread.getThreadName(), true);
        }
    }
27017
public void stop() {
        synchronized (this.startStopMonitor) {
            doStop();

            // If we registered a JVM shutdown hook, we don't need it anymore now:
            // We've already explicitly closed the context.
            if (this.shutdownHook != null) {
                try {
                    Runtime.getRuntime().removeShutdownHook(this.shutdownHook);
                } catch (final IllegalStateException ex) {
                    // ignore - VM is already shutting down
                }
            }
        }
    }
1320946
void shutdownNow() {
    shutdown = true;
    for (int i = 0; i < channels.length; i++) {
      // Initiate channel shutdown
      channels[i].shutdown();
    }
    for (int i = 0; i < channels.length; i++) {
      try {
        // Wait for channel termination
        channels[i].awaitTermination(1, TimeUnit.SECONDS);
      } catch (InterruptedException ie) {
        channels[i].shutdownNow();
      }
    }
    fixedThreadPool.shutdownNow();
  }
872926
function cleanup (exitCode) {
  if(_disabled) {
    return q.resolve();
  }

  var defer = q.defer();

  _readRunIdFile().then(function (run) {
    _logMessage('test finished. Your results can be viewed at: ' +
      'http://' + _hostname + ':' + _port + '/#/' + run.project_id + '/' + run.suite_id + '/' + run.run_id + '/rp');
    fs.unlink(RUN_PID_FILE, function (err) {
      if (err) {
        defer.reject(err);
      } else {
        defer.resolve();
      }
    });
  });

  return defer.promise;
}
1055946
function ( callbackOnFinishedProcessing ) {
		if ( this.logging.enabled ) console.info( 'WorkerDirector received the deregister call. Terminating all workers!' );

		this.instructionQueuePointer = this.instructionQueue.length;
		this.callbackOnFinishedProcessing = THREE.LoaderSupport.Validator.verifyInput( callbackOnFinishedProcessing, null );

		for ( var name in this.workerDescription.workerSupports ) {

			this.workerDescription.workerSupports[ name ].terminateRequested = true;

		}
	}
1373389
@Override
    public void shutdown() {
        try {
            verifyMaintainability();
        } catch (VerificationFailedException ex) {
            throw new RuntimeException("Can not shutdown " + this + "!", ex);
        }

        this.shutdownInitiated = true;
        try {
            dataObservable.shutdown();
        } finally {
            try {
                deactivate();
            } catch (CouldNotPerformException | InterruptedException ex) {
                ExceptionPrinter.printHistory("Could not shutdown " + this + "!", ex, logger);
            }
        }
    }
1208805
void shutdown() throws InterruptedException {
        m_shouldStop = true;
        if (m_thread != null) {
            m_selector.wakeup();
            m_thread.join();
        }
    }
951287
private Status executeFail(Stmt.Fail stmt, CallStack frame, EnclosingScope scope) {
		throw new AssertionError("Runtime fault occurred");
	}
969802
def shutdown(self):
        """"""
        # cleanup
        self.started = False
        try:
            # nice way of doing things - let's wait until all items
            # in the queue are processed
            for t in self._threads:
                t.join()
        finally:
            # Emergency brake - if a KeyboardInterrupt is raised,
            # threads will finish processing current task and exit
            self.stopped = True
693797
function (msg) {
        // restart MutexJs in case exception caused fatal javascript halt
        MutexJs.recover();

        // unexpected exception so log in errors and move to next
        var t = PFT.tester.currentTest();
        t.errors.push(msg);
        PFT.tester.onError({ test: t, message: msg });

        PFT.tester.closeTest(t);
        // move to next test
        MutexJs.release(t.runUnlockId);
    }
580959
@Override
    public void close() {
        try {
            // Prevent new tasks being submitted
            shutdown();
        } catch (final SecurityException e) {
            // Ignore for now (caught again if shutdownNow() fails)
        }
        boolean terminated = false;
        try {
            // Await termination of any running tasks
            terminated = awaitTermination(2500, TimeUnit.MILLISECONDS);
        } catch (final InterruptedException e) {
            interruptionChecker.interrupt();
        }
        if (!terminated) {
            try {
                // Interrupt all the threads to terminate them, if awaitTermination() timed out
                shutdownNow();
            } catch (final SecurityException e) {
                throw ClassGraphException.newClassGraphException("Could not shut down ExecutorService -- need "
                        + "java.lang.RuntimePermission(\"modifyThread\"), "
                        + "or the security manager's checkAccess method denies access", e);
            }
        }
    }
1002717
def shutdown(self):
        

        if not self._exited:
            self._exited = True
            _shutdown_pipe(self._pipe)
            self._task.stop()
            raise SystemExit
710156
function() {
        if (this._isShuttingDown) {
            return;
        }
        this._isShuttingDown = true;

        // Restart but wait a bit to log things.
        // -R - restart
        // -C - shutdown message
        // -T 0 - shutdown now
        // -F - don't wait for anything to shut down gracefully
        var winCmd = 'shutdown -R -T 0 -F -C "ampm restart"';
        var macCmd = 'shutdown -r now';
        var cmd = process.platform === 'win32' ? winCmd : macCmd;
        setTimeout(child_process.exec(cmd), 3000);
    }
1173998
private void doInterruptAllWaitingThreads() {
    	//Interrupt all the threads
    	for (int i=0; i<nThreads; i++) {
    		threads[i].interrupt();
    	}
    	
    	synchronized(lock) {
    		lock.notify();
    	}
    }
395266
def consumer_shutdown_task(processor, check_point_tracker):
    
    exception = None
    try:
        processor.shutdown(check_point_tracker)
    except Exception as e:
        print(e)
        exception = None

    try:
        check_point_tracker.get_check_point()
    except Exception:
        logger.error('Failed to flush check point', exc_info=True)

    return TaskResult(exception)
911288
synchronized void deactivate() {
        paused = false;
        if (activeTask != null) {
            activeTask.cancel();
            activeTask = null;
        }
        this.threadPool = null;
    }
693981
def shutdown():
    '''
    '''
    global _sdk_ref_count #pylint:disable=global-statement
    global _sdk_instance #pylint:disable=global-statement
    global _should_shutdown #pylint:disable=global-statement

    with _sdk_ref_lk:
        logger.debug("shutdown: ref count = %d, should_shutdown = %s", \
                     _sdk_ref_count, _should_shutdown)
        nsdk = nativeagent.try_get_sdk()
        if not nsdk:
            logger.warning('shutdown: SDK not initialized or already shut down')
            _sdk_ref_count = 0
            return None
        if _sdk_ref_count > 1:
            logger.debug('shutdown: reference count is now %d', _sdk_ref_count)
            _sdk_ref_count -= 1
            return None
        logger.info('shutdown: Shutting down SDK.')
        try:
            if _should_shutdown:
                _rc = nsdk.shutdown()
                if _rc == ErrorCode.NOT_INITIALIZED:
                    logger.warning('shutdown: native SDK was not initialized')
                else:
                    nativeagent.checkresult(nsdk, _rc, 'shutdown')
                _should_shutdown = False
        except SDKError as e:
            logger.warning('shutdown failed', exc_info=sys.exc_info())
            return e
        _sdk_ref_count = 0
        _sdk_instance = None
        nativeagent._force_initialize(None) #pylint:disable=protected-access
        logger.debug('shutdown: completed')
        return None