If a runnable is a daemon, it will not keep the main loop running. The main loop will end when all alived runnables are daemons.
350751
def setDaemon(self, runnable, isdaemon, noregister = False):
        '''
        
        '''
        if not noregister and runnable not in self.registerIndex:
            self.register((), runnable)
        if isdaemon:
            self.daemons.add(runnable)
        else:
            self.daemons.discard(runnable)
305483
void doExclusive(Runnable runnable) {

        LettuceAssert.notNull(runnable, "Runnable must not be null");

        doExclusive(() -> {
            runnable.run();
            return null;
        });
    }
1014401
private void start(boolean daemon) {
        if (daemon == Thread.currentThread().isDaemon()) {
            server.start();
        } else {
            FutureTask<Void> startTask = new FutureTask<Void>(new Runnable() {
                @Override
                public void run() {
                    server.start();
                }
            }, null);
            NamedDaemonThreadFactory.defaultThreadFactory(daemon).newThread(startTask).start();
            try {
                startTask.get();
            } catch (ExecutionException e) {
                throw new RuntimeException("Unexpected exception on starting HTTPSever", e);
            } catch (InterruptedException e) {
                // This is possible only if the current tread has been interrupted,
                // but in real use cases this should not happen.
                // In any case, there is nothing to do, except to propagate interrupted flag.
                Thread.currentThread().interrupt();
            }
        }
    }
297563
public C run(Runnable runnable) throws SniffyAssertionError {
        checkOpened();
        try {
            runnable.run();
        } catch (Throwable e) {
            throw verifyAndAddToException(e);
        }

        verify();
        return self();
    }
1141605
public static void runIntoJAT(final JRebirthRunnable runnable) {
        if (Platform.isFxApplicationThread()) {
            // We are into a JAT so just run it synchronously
            runnable.run();
        } else {
            // The runnable will be run into the JAT during the next round
            Platform.runLater(runnable);
        }
    }
1352113
function(isnodeObj){
		if(initialised)
			return ismod;
		isnode = isnodeObj;
		log = isnode.module("logger").log;
		isnode.on("startDaemon", function(){
			if(!process.send) {
				run({name: isnode.pkg().name, isChildProcess: process.send});
			} else {
				log("fatal", "Daemon Initiated, but running in daemon mode. Terminating application.");
			}
		});
		isnode.on("shutdown", function(){ shutdown(); });
		initialised = true;
		return ismod;
	}
709224
public static Atomic atomic(Runnable runnable) {
        try {
            AnimaQuery.beginTransaction();
            runnable.run();
            AnimaQuery.commit();
            return Atomic.ok();
        } catch (Exception e) {

            boolean isRollback = ifReturn(
                    of().rollbackException.isInstance(e),
                    () -> {
                        AnimaQuery.rollback();
                        return true;
                    },
                    () -> false);

            return Atomic.error(e).rollback(isRollback);
        } finally {
            AnimaQuery.endTransaction();
        }
    }
900958
protected Runnable getNextRunnable() throws InterruptedException {

        Runnable toRun = null;

        // Wait for new Runnable (see runInThread()) and notify runInThread()
        // in case the next Runnable is already waiting.
        synchronized (m_nextRunnableLock) {
            if (m_nextRunnable == null) {
                m_nextRunnableLock.wait(1000);
            }

            if (m_nextRunnable != null) {
                toRun = m_nextRunnable;
                m_nextRunnable = null;
                m_nextRunnableLock.notifyAll();
            }
        }

        return toRun;
    }
333214
@Override
    public void postToMainThread(Runnable runnable) {
        if (mMainHandler == null) {
            synchronized (mLock) {
                if (mMainHandler == null) {
                    mMainHandler = new Handler(Looper.getMainLooper());
                }
            }
        }
        //noinspection ConstantConditions
        mMainHandler.post(runnable);
    }
553427
@Override
   public void run()
   {
      try {
         startBarrier.await();

         int idleCount = 0;
         while (!isRunning.compareAndSet(idleCount > LINGER_ITERATIONS && deadPool.isEmpty() && completionKeyToProcessMap.isEmpty(), false)) {
            idleCount = (!shutdown && process()) ? 0 : (idleCount + 1);
         }
      }
      catch (Exception e) {
         // TODO: how to handle this error?
         e.printStackTrace();
         isRunning.set(false);
      }
   }
1248376
def daemon(self):
        
        if self._process:
            return self._process.daemon
        else:
            return self._pargs.get('daemonic', False)
1257107
public static boolean ifTrue(final Boolean bool, final Runnable runnable) {
        if (isTrue(bool)) {
            runnable.run();
            return true;
        }
        return false;
    }
118172
private boolean mainLoop()
        throws InterruptedException
    {
        long now = System.currentTimeMillis();
        Iterator list = m_hardStore.values().iterator();
        while( list.hasNext() )
        {
            Entry entry = (Entry) list.next();
            if( entry.m_collectTime < now )
            {
                m_weakStore.put( entry.m_connection, DUMMY );
                list.remove();
            }
        }
        if( m_hardStore.size() == 0 )
        {
            m_thread = null;    // mark to start a new thread next time.
            return true;
        }
        wait( 10000 );
        return false;
    }
140798
def start_daemon_thread(target, args=()):
    """"""
    th = Thread(target=target, args=args)
    th.daemon = True
    th.start()
    return th
731337
def run_daemon(self):
        
        try:
            self.daemon_runner.do_action()
        except daemon.runner.DaemonRunnerStopFailureError:
            self.onStopFail()
        except SystemExit:
            self.onExit()
940205
def start_daemon_thread(*args, **kwargs):
    """"""
    thread = threading.Thread(*args, **kwargs)
    thread.daemon = True
    thread.start()
    return thread
709101
def is_alive(self):
        

        if self.exit_code is not None:
            return False, self.exit_code

        # what we're doing here essentially is making sure that the main thread
        # (or another thread), isn't calling .wait() on the process.  because
        # .wait() calls os.waitpid(self.pid, 0), we can't do an os.waitpid
        # here...because if we did, and the process exited while in this
        # thread, the main thread's os.waitpid(self.pid, 0) would raise OSError
        # (because the process ended in another thread).
        #
        # so essentially what we're doing is, using this lock, checking if
        # we're calling .wait(), and if we are, let .wait() get the exit code
        # and handle the status, otherwise let us do it.
        acquired = self._wait_lock.acquire(False)
        if not acquired:
            if self.exit_code is not None:
                return False, self.exit_code
            return True, self.exit_code

        try:
            # WNOHANG is just that...we're calling waitpid without hanging...
            # essentially polling the process.  the return result is (0, 0) if
            # there's no process status, so we check that pid == self.pid below
            # in order to determine how to proceed
            pid, exit_code = no_interrupt(os.waitpid, self.pid, os.WNOHANG)
            if pid == self.pid:
                self.exit_code = handle_process_exit_code(exit_code)
                self._process_just_ended()

                return False, self.exit_code

        # no child process
        except OSError:
            return False, self.exit_code
        else:
            return True, self.exit_code
        finally:
            self._wait_lock.release()