Example #1
0
    def test_block(self):
        b = wspbus.Bus()
        self.log(b)

        def f():
            time.sleep(0.2)
            b.exit()
        def g():
            time.sleep(0.4)
        threading.Thread(target=f).start()
        threading.Thread(target=g).start()
        threads = [t for t in threading.enumerate() if not get_daemon(t)]
        self.assertEqual(len(threads), 3)

        b.block()

        # The block method MUST wait for the EXITING state.
        self.assertEqual(b.state, b.states.EXITING)
        # The block method MUST wait for ALL non-main, non-daemon threads to finish.
        threads = [t for t in threading.enumerate() if not get_daemon(t)]
        self.assertEqual(len(threads), 1)
        # The last message will mention an indeterminable thread name; ignore it
        self.assertEqual(self._log_entries[:-1],
                         ['Bus STOPPING', 'Bus STOPPED',
                          'Bus EXITING', 'Bus EXITED',
                          'Waiting for child threads to terminate...'])
Example #2
0
    def test_block(self):
        b = wspbus.Bus()
        self.log(b)

        def f():
            time.sleep(0.2)
            b.exit()

        def g():
            time.sleep(0.4)

        threading.Thread(target=f).start()
        threading.Thread(target=g).start()
        threads = [t for t in threading.enumerate() if not get_daemon(t)]
        self.assertEqual(len(threads), 3)

        b.block()

        # The block method MUST wait for the EXITING state.
        self.assertEqual(b.state, b.states.EXITING)
        # The block method MUST wait for ALL non-main, non-daemon threads to
        # finish.
        threads = [t for t in threading.enumerate() if not get_daemon(t)]
        self.assertEqual(len(threads), 1)
        # The last message will mention an indeterminable thread name; ignore
        # it
        self.assertEqual(self._log_entries[:-1], [
            'Bus STOPPING', 'Bus STOPPED', 'Bus EXITING', 'Bus EXITED',
            'Waiting for child threads to terminate...'
        ])
Example #3
0
 def stop(self):
     if self.thread is None:
         self.bus.log('No thread running for %s.' % self.name or self.__class__.__name__)
     else:
         if self.thread is not threading.currentThread():
             name = self.thread.getName()
             self.thread.cancel()
             if not get_daemon(self.thread):
                 self.bus.log('Joining %r' % name)
                 self.thread.join()
             self.bus.log('Stopped thread %r.' % name)
         self.thread = None
Example #4
0
 def stop(self):
     """Stop our callback's background task thread."""
     if self.thread is None:
         self.bus.log("No thread running for %s." % self.name or self.__class__.__name__)
     else:
         if self.thread is not threading.currentThread():
             name = self.thread.getName()
             self.thread.cancel()
             if not get_daemon(self.thread):
                 self.bus.log("Joining %r" % name)
                 self.thread.join()
             self.bus.log("Stopped thread %r." % name)
         self.thread = None
Example #5
0
 def stop(self):
     if self.thread is None:
         self.bus.log('No thread running for %s.' % self.name
                      or self.__class__.__name__)
     else:
         if self.thread is not threading.currentThread():
             name = self.thread.getName()
             self.thread.cancel()
             if not get_daemon(self.thread):
                 self.bus.log('Joining %r' % name)
                 self.thread.join()
             self.bus.log('Stopped thread %r.' % name)
         self.thread = None
Example #6
0
File: plugins.py Project: xyb/0bin
 def stop(self):
     """Stop our callback's background task thread."""
     if self.thread is None:
         self.bus.log("No thread running for %s." % self.name or self.__class__.__name__)
     else:
         if self.thread is not threading.currentThread():
             name = self.thread.getName()
             self.thread.cancel()
             if not get_daemon(self.thread):
                 self.bus.log("Joining %r" % name)
                 self.thread.join()
             self.bus.log("Stopped thread %r." % name)
         self.thread = None
Example #7
0
    def test_block(self):
        b = wspbus.Bus()
        self.log(b)

        def f():
            time.sleep(0.2)
            b.exit()

        def g():
            time.sleep(0.4)

        threading.Thread(target=f).start()
        threading.Thread(target=g).start()
        threads = [t for t in threading.enumerate() if not get_daemon(t)]
        self.assertEqual(len(threads), 3)
        b.block()
        self.assertEqual(b.state, b.states.EXITING)
        threads = [t for t in threading.enumerate() if not get_daemon(t)]
        self.assertEqual(len(threads), 1)
        self.assertEqual(self._log_entries[:-1], [
            'Bus STOPPING', 'Bus STOPPED', 'Bus EXITING', 'Bus EXITED',
            'Waiting for child threads to terminate...'
        ])
Example #8
0
    def test_block(self):
        b = wspbus.Bus()
        self.log(b)

        def f():
            time.sleep(0.2)
            b.exit()

        def g():
            time.sleep(0.4)

        threading.Thread(target=f).start()
        threading.Thread(target=g).start()
        threads = [ t for t in threading.enumerate() if not get_daemon(t) ]
        self.assertEqual(len(threads), 3)
        b.block()
        self.assertEqual(b.state, b.states.EXITING)
        threads = [ t for t in threading.enumerate() if not get_daemon(t) ]
        self.assertEqual(len(threads), 1)
        self.assertEqual(self._log_entries[:-1], ['Bus STOPPING',
         'Bus STOPPED',
         'Bus EXITING',
         'Bus EXITED',
         'Waiting for child threads to terminate...'])