Browse files

Add new daemon kwarg to for threaded main loops

This replaces the kludge that tries to detect if Python is running
interactively.  Instead daemon=True by default and the user can override
that as needed.
  • Loading branch information...
1 parent 1c994e9 commit 9db8b1f559ea43eb05480baf8ae53b2014b309c5 @jtackaberry jtackaberry committed Jan 24, 2012
Showing with 6 additions and 8 deletions.
  1. +6 −8 src/
@@ -222,7 +222,7 @@ def loop(condition, timeout=None):
-def run(threaded=False):
+def run(threaded=False, daemon=True):
Start the main loop.
@@ -233,6 +233,10 @@ def run(threaded=False):
:param threaded: if True, the Kaa mainloop will start in a new thread.
:type threaded: bool
+ :param daemon: applies when ``threaded=True``, and indicates if the thread
+ running the main loop is a daemon thread. Daemon threads will
+ not block the program from exiting when the main Python thread
+ terminates.
Specifying ``threaded=True`` is useful if the main Python thread has been
co-opted by another mainloop framework and you want to use Kaa in parallel.
@@ -267,13 +271,7 @@ def run(threaded=False):
event = threading.Event()
t = threading.Thread(target=run, name='kaa mainloop')
- if 'readline' in sys.modules:
- # If the readline module is loaded, this almost certainly means
- # that we're running interactively. If so, and the main loop is
- # being run in a separate thread, make that thread a daemon thread
- # so when the user exits the interactive interpreter it doesn't
- # block.
- t.setDaemon(True)
+ t.setDaemon(daemon)
return event.wait()

0 comments on commit 9db8b1f

Please sign in to comment.