Does the Python framework nose support testing a function which inititializes a daemon thread
Question: I am new on Stackoverflow and at Python. I wrote a simple Python program as
follows:

    
    
    from threading import Thread
    from Queue import Queue
    
    import time
    g_log_queue = Queue()
    def print_log():
            while True:
                    record = g_log_queue.get()
                    if record == 'a':
                            print 'a is out'
                    elif record == 'b':
                            print 'b is out'
                    else:
                            print 'other is out'    
    
    
    def run():
            g_log_thread = Thread(target=print_log,name='logthread',args=())
            g_log_thread.daemon = True
            g_log_thread.start()
    
            g_log_queue.put('a')
            g_log_queue.put('b')
            g_log_queue.put('c')
    
    run()
    

Now, I write a demo test case for the program as follows:

    
    
    from nose.tools import *
    from pdaemon import *
    
    
    def test_run():
            run()
    

When I run the nosetest command, I get this message:

    
    
    .
    ----------------------------------------------------------------------
    Ran 1 test in 0.003s
    
    OK
    Exception in thread logthread (most likely raised during interpreter shutdown):
    Traceback (most recent call last):
      File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
      File "/usr/lib/python2.7/threading.py", line 505, in run
      File "/root/python/daemon/pdaemon.py", line 7, in print_log
      File "/usr/lib/python2.7/Queue.py", line 179, in get
      File "/usr/lib/python2.7/threading.py", line 279, in notify
    <type 'exceptions.TypeError'>: 'NoneType' object is not callable
    

Do nose support testing the function which initializes a daemon thread?


Answer: It's the python bug <http://bugs.python.org/issue14623> The workaround is to
add timeout

    
    
    time.sleep(1)
    

in the end of script that allows the threads to finish before the script comes
to end of life and close

