import functools, time, unittest
from bibliopixel.threads import sub

WAIT_FOR_SUB = 0.1


def pause(delay=0.005):
    time.sleep(delay)


def run(input, output, *arg, **kwds):
    pause()

    if arg != (1, 2, 3):
        raise ValueError('1 2 3')

    if kwds != dict(a=1):
        raise ValueError('a=1')

    pause()


class SubTest(unittest.TestCase):
    def do_test(self, use_subprocess):
        s, i, o = sub.run(run, 1, 2, 3, a=1, use_subprocess=use_subprocess)
        self.assertTrue(s.is_alive())
        pause()
        self.assertTrue(s.is_alive())

        pause(WAIT_FOR_SUB)
        self.assertFalse(s.is_alive())

    def test_subprocess(self):
        self.do_test(True)

    def test_threading(self):
        self.do_test(False)

@@ -107,10 +107,9 @@
 =0.0
-05
+1
 ):%0A 
@@ -182,16 +182,41 @@
 ause()%0A%0A
+    output.put('first')%0A%0A
     if a
@@ -338,16 +338,41 @@
 pause()%0A
+    output.put('second')%0A
 %0A%0Aclass 
@@ -454,22 +454,44 @@
 s, i
-, o = sub.run(
+nput, output = sub.run(%0A            
 run,
@@ -578,30 +578,62 @@
 ())%0A        
-pause(
+self.assertEqual(output.get(), 'first'
 )%0A        se
@@ -656,24 +656,72 @@
 is_alive())%0A
+        self.assertEqual(output.get(), 'second')
 %0A        pau
@@ -723,28 +723,16 @@
   pause(
-WAIT_FOR_SUB
 )%0A      

Change sub_test to use its queues.