Пример #1
0
class SignalHandlerTest(TestCase):
    def setUp(self):
        self.loop = MessageSendingLoop()

    def test_signal_handler_installation_removal(self):
        """
        Make sure we can install and remove signal handlers, and that they get
        updated appropriately.
        """
        saved = dict([(s, signal.getsignal(s)) for s in self.loop.signals])
        self.loop._install_signal_handlers()
        for sig in self.loop.signals:
            self.assertEqual(signal.getsignal(sig), self.loop._signal_handler)
        self.loop._restore_signal_handlers()
        for sig in self.loop.signals:
            self.assertEqual(signal.getsignal(sig), saved[sig])

    def test_signal_handler_parent_proc(self):
        """
        Test signal as if it arrived in the parent process.
        """
        self.loop._running = True
        self.loop._signal_handler(signal.SIGHUP, None)
        self.assertFalse(self.loop._running)
        # make sure running again doesn't raise an error
        self.loop._signal_handler(signal.SIGHUP, None)

    def test_signal_handler_child_proc_ignored(self):
        """
        Test signal as if it arrived in a child process.
        """
        self.loop._parent_pid = os.getpid() + 1  # anything other than os.getpid()
        self.loop._running = True
        self.loop._signal_handler(signal.SIGHUP, None)
        self.assertTrue(self.loop._running)
Пример #2
0
 def handle(self, *args, **options):
     msgs_per_sec = options['msgs_per_sec']
     concurrent_workers = options['concurrent_workers']
     send_forever = options['send_forever']
     # if we were called from the command line (and not from a unit test or
     # other Python method), show log messages on the console, too
     cmd_name = __name__.split('.')[-1]
     if cmd_name in sys.argv:
         logging.getLogger('bulk_sms').addHandler(logging.StreamHandler())
     # start the message sending loop, which returns after one group of
     # messages is sent if send_forever is False. Otherwise, it loops
     # indefinitely and returns only upon receipt of a SIGINT, SIGTERM, or SIGHUP
     mainloop = MessageSendingLoop(msgs_per_sec, concurrent_workers)
     mainloop.send(forever=send_forever)
Пример #3
0
 def handle(self, *args, **options):
     msgs_per_sec = options['msgs_per_sec']
     concurrent_workers = options['concurrent_workers']
     send_forever = options['send_forever']
     # if we were called from the command line (and not from a unit test or
     # other Python method), show log messages on the console, too
     cmd_name = __name__.split('.')[-1]
     if cmd_name in sys.argv:
         logging.getLogger('bulk_sms').addHandler(logging.StreamHandler())
     # start the message sending loop, which returns after one group of
     # messages is sent if send_forever is False. Otherwise, it loops
     # indefinitely and returns only upon receipt of a SIGINT, SIGTERM, or SIGHUP
     mainloop = MessageSendingLoop(msgs_per_sec, concurrent_workers)
     mainloop.send(forever=send_forever)
Пример #4
0
class SignalHandlerTest(TestCase):
    def setUp(self):
        self.loop = MessageSendingLoop()

    def test_signal_handler_installation_removal(self):
        """
        Make sure we can install and remove signal handlers, and that they get
        updated appropriately.
        """
        saved = dict([(s, signal.getsignal(s)) for s in self.loop.signals])
        self.loop._install_signal_handlers()
        for sig in self.loop.signals:
            self.assertEqual(signal.getsignal(sig), self.loop._signal_handler)
        self.loop._restore_signal_handlers()
        for sig in self.loop.signals:
            self.assertEqual(signal.getsignal(sig), saved[sig])

    def test_signal_handler_parent_proc(self):
        """
        Test signal as if it arrived in the parent process.
        """
        self.loop._running = True
        self.loop._signal_handler(signal.SIGHUP, None)
        self.assertFalse(self.loop._running)
        # make sure running again doesn't raise an error
        self.loop._signal_handler(signal.SIGHUP, None)

    def test_signal_handler_child_proc_ignored(self):
        """
        Test signal as if it arrived in a child process.
        """
        self.loop._parent_pid = os.getpid(
        ) + 1  # anything other than os.getpid()
        self.loop._running = True
        self.loop._signal_handler(signal.SIGHUP, None)
        self.assertTrue(self.loop._running)
Пример #5
0
 def setUp(self):
     self.loop = MessageSendingLoop()
Пример #6
0
 def setUp(self):
     self.loop = MessageSendingLoop()