Exemple #1
0
 def __call__(self):
     if uwsgi.mule_id() == 0:
         return
     if not uwsgi.in_farm(self.farm):
         return
     while True:
         message = uwsgi.farm_get_msg()
         if message:
             self.f(message)
Exemple #2
0
 def _dispatch_messages(self):
     # this could be moved to the base class if locking was abstracted and a get_message method was added
     log.info('Application stack message dispatcher thread starting up')
     # we are going to do this a lot, so cache the lock number
     lock = self._farm_recv_msg_lock_num()
     while self.running:
         msg = None
         self.__lock(lock)
         try:
             log.debug('Acquired message lock, waiting for new message')
             msg = unicodify(uwsgi.farm_get_msg())
             log.debug('Received message: %s', msg)
             if msg == self.SHUTDOWN_MSG:
                 self.running = False
             else:
                 self.dispatcher.dispatch(msg)
         except Exception:
             log.exception('Exception in mule message handling')
         finally:
             self.__unlock(lock)
             log.debug('Released lock')
     log.info('Application stack message dispatcher thread exiting')
Exemple #3
0
 def _dispatch_messages(self):
     # this could be moved to the base class if locking was abstracted and a get_message method was added
     log.info('Application stack message dispatcher thread starting up')
     # we are going to do this a lot, so cache the lock number
     lock = self._farm_recv_msg_lock_num()
     while self.running:
         msg = None
         self.__lock(lock)
         try:
             log.debug('Acquired message lock, waiting for new message')
             msg = unicodify(uwsgi.farm_get_msg())
             log.debug('Received message: %s', msg)
             if msg == self.SHUTDOWN_MSG:
                 self.running = False
             else:
                 self.dispatcher.dispatch(msg)
         except Exception:
             log.exception('Exception in mule message handling')
         finally:
             self.__unlock(lock)
             log.debug('Released lock')
     log.info('Application stack message dispatcher thread exiting')
Exemple #4
0
import signal, sys
import time
import uwsgi
import os

print(uwsgi.opt)

sig_timeout = uwsgi.opt.get('test_mule_timeout', 10)
sig_to_send = uwsgi.opt.get('test_signal', signal.SIGINT)

def sig_handler(signum, frame):
    print('Hello from signal', signum)
    time.sleep(int(sig_timeout))
    sys.exit(0)

signal.signal(signal.SIGINT, sig_handler)
signal.signal(signal.SIGHUP, sig_handler)

time.sleep(1)

os.kill(uwsgi.masterpid(), int(sig_to_send))

while True:
    uwsgi.farm_get_msg()
Exemple #5
0
import signal, sys
import time
import uwsgi
import os

print(uwsgi.opt)

sig_timeout = uwsgi.opt.get('test_mule_timeout', 10)
sig_to_send = uwsgi.opt.get('test_signal', signal.SIGINT)


def sig_handler(signum, frame):
    print('Hello from signal', signum)
    time.sleep(int(sig_timeout))
    sys.exit(0)


signal.signal(signal.SIGINT, sig_handler)
signal.signal(signal.SIGHUP, sig_handler)

time.sleep(1)

os.kill(uwsgi.masterpid(), int(sig_to_send))

while True:
    uwsgi.farm_get_msg()