parameters: ()
docstring: Wait until the Python thread state of all non-daemon threads get deleted.
docstring_summary: Wait until the Python thread state of all non-daemon threads get deleted.
docstring_tokens: Wait until the Python thread state of all non - daemon threads get deleted .
function: def _shutdown():
      """
      Wait until the Python thread state of all non-daemon threads get deleted.
      """
      # Obscure:  other threads may be waiting to join _main_thread.  That's
      # dubious, but some code does it.  We can't wait for C code to release
      # the main thread's tstate_lock - that won't happen until the interpreter
      # is nearly dead.  So we release it here.  Note that just calling _stop()
      # isn't enough:  other threads may already be waiting on _tstate_lock.
      if _main_thread._is_stopped:
          # _shutdown() was already called
          return
  
      # Main thread
      tlock = _main_thread._tstate_lock
      # The main thread isn't finished yet, so its thread state lock can't have
      # been released.
      assert tlock is not None
      assert tlock.locked()
      tlock.release()
      _main_thread._stop()
  
      # Join all non-deamon threads
      while True:
          with _shutdown_locks_lock:
              locks = list(_shutdown_locks)
              _shutdown_locks.clear()
  
          if not locks:
              break
  
          for lock in locks:
              # mimick Thread.join()
              lock.acquire()
              lock.release()
function_tokens: def _shutdown ( ) : # Obscure:  other threads may be waiting to join _main_thread.  That's # dubious, but some code does it.  We can't wait for C code to release # the main thread's tstate_lock - that won't happen until the interpreter # is nearly dead.  So we release it here.  Note that just calling _stop() # isn't enough:  other threads may already be waiting on _tstate_lock. if _main_thread . _is_stopped : # _shutdown() was already called return # Main thread tlock = _main_thread . _tstate_lock # The main thread isn't finished yet, so its thread state lock can't have # been released. assert tlock is not None assert tlock . locked ( ) tlock . release ( ) _main_thread . _stop ( ) # Join all non-deamon threads while True : with _shutdown_locks_lock : locks = list ( _shutdown_locks ) _shutdown_locks . clear ( ) if not locks : break for lock in locks : # mimick Thread.join() lock . acquire ( ) lock . release ( )