Unschedule task if active, and cancel thread to inform it must be interrupted in a proper way.
555267
public void unscheduleTask() {
    if (unschedule.compareAndSet(false, true)) {
      scheduledFuture.cancel(false);
      scheduledFuture = null;
    }

  }
543362
def thread_stopped(self):
		
		if self.__current_task is not None:
			task = self.__task_chain[self.__current_task]
			task.stop()
			self.__current_task = None
1173998
private void doInterruptAllWaitingThreads() {
    	//Interrupt all the threads
    	for (int i=0; i<nThreads; i++) {
    		threads[i].interrupt();
    	}
    	
    	synchronized(lock) {
    		lock.notify();
    	}
    }
385883
public void cancelScheduledTask(TimerTask task) {
		TaskEngine.TimerTaskWrapper taskWrapper = wrappedTasks.remove(task);
		if (taskWrapper != null) {
			taskWrapper.cancel();
		}
	}
340208
def do_cancel(self, taskid: int) -> None:
        """"""
        task = task_by_id(taskid, self._loop)
        if task:
            fut = asyncio.run_coroutine_threadsafe(
                cancel_task(task), loop=self._loop)
            fut.result(timeout=3)
            self._sout.write('Cancel task %d\n' % taskid)
        else:
            self._sout.write('No task %d\n' % taskid)
294902
def __thread_started(self):
		
		if self.__task is None:
			raise RuntimeError('Unable to start thread without "start" method call')
		self.__task.start()
		self.__task.start_event().wait(self.__scheduled_task_startup_timeout__)
930640
void suspendTask(final byte[] message) {
    synchronized (this.contextLifeCycle) {
      if (!this.task.isPresent()) {
        LOG.log(Level.WARNING, "Received a suspend task while there was no task running. Ignoring.");
      } else {
        this.task.get().suspend(message);
      }
    }
  }
786929
void tearDown() throws InterruptedException {
    if (cancelFuture != null) {
      cancelFuture.cancel(false);
    }
    executor.shutdown();
    executor.awaitTermination(10, TimeUnit.SECONDS);
  }
1359634
async def cancel(self):
        """"""
        self.is_cancelled = True
        if self.future is not None:
            self.future.cancel()
        if self.task_process is not None:
            log.warning("Worker is shutting down, but a task is running. Terminating task")
            await self.task_process.worker_shutdown_stop()
436541
async def stop(self):
        """"""

        if self._rpc_task is not None:
            self._rpc_task.cancel()

        try:
            await self._rpc_task
        except asyncio.CancelledError:
            pass

        self._rpc_task = None
81086
public void stop() {
		if (schedulerThread != null) {
			schedulerThread.interrupt();
			try {
				schedulerThread.join(1000);
			} catch (InterruptedException ie) {
			}
//			application.releaseRequest(schedulerThread);
			schedulerThread = null;

			System.out.println(new LogEntry("scheduler thread stopped..."));
		}
	}
1368605
@Handler(priority = -10000)
    public void onStop(Stop event) throws InterruptedException {
        synchronized (this) {
            if (runner == null) {
                return;
            }
            // It just might happen that the wakeup() occurs between the
            // check for running and the select() in the thread's run loop,
            // but we -- obviously -- cannot put the select() in a
            // synchronized(this).
            while (runner.isAlive()) {
                runner.interrupt(); // *Should* be sufficient, but...
                selector.wakeup(); // Make sure
                runner.join(10);
            }
            runner = null;
        }
    }
580353
def stopThread(self):
        """"""
        if self._thread is not None:
            self.performSelector_onThread_withObject_waitUntilDone_('stopPowerNotificationsThread', self._thread, None, objc.YES)
            self._thread = None
157532
void stopNow() {
        assert currentThread() != this : "stopNow must not be called on the migration thread";
        running = false;
        queue.clear();
        interrupt();
        boolean currentThreadInterrupted = false;
        while (true) {
            try {
                join();
            } catch (InterruptedException e) {
                currentThreadInterrupted = true;
                continue;
            }
            break;
        }
        if (currentThreadInterrupted) {
            currentThread().interrupt();
        }
    }
256141
public final void cancel(CancelException reason) {
		if (cancelling != null)
			return;
		if (reason == null) reason = new CancelException("No reason given");
		cancelling = reason;
		if (TaskScheduler.cancel(this)) {
			status = Task.STATUS_DONE;
			result.cancelled(reason);
			return;
		}
		if (manager.remove(this)) {
			status = Task.STATUS_DONE;
			result.cancelled(reason);
			return;
		}
		if (status == Task.STATUS_NOT_STARTED) {
			status = Task.STATUS_DONE;
			result.cancelled(reason);
			return;
		}
	}
1358889
def unschedule(self, task_name):
        '''
        
        '''
        for greenlet in self.waiting[task_name]:
            try:
                gevent.kill(greenlet)
            except BaseException:
                pass
1208805
void shutdown() throws InterruptedException {
        m_shouldStop = true;
        if (m_thread != null) {
            m_selector.wakeup();
            m_thread.join();
        }
    }