コード例 #1
0
ファイル: threadmgr.py プロジェクト: pombredanne/kunai-1
        def w(is_essential):
            tid = 0
            if libc:
                tid = libc.syscall(186)  # get the threadid when you are in it :)
            logger.info("THREAD launch (%s) with thread id (%d)" % (name, tid))
            try:
                f(*args)
            except Exception, exp:
                output = cStringIO.StringIO()
                traceback.print_exc(file=output)
                logger.error("Thread %s is exiting on error. Back trace of this error: %s" % (name, output.getvalue()))
                output.close()

                if is_essential:
                    # Maybe the thread WAS an essential one (like http thread or something like this), if so
                    # catch it and close the whole daemon
                    logger.error(
                        "The thread %s was an essential one, we are stopping the daemon do not be in an invalid state"
                        % name
                    )
                    pubsub.pub("interrupt")
コード例 #2
0
ファイル: gossip.py プロジェクト: pombredanne/kunai-1
 def do_push_pull(self, other):
     nodes = {}
     with self.nodes_lock:
         nodes = copy.copy(self.nodes)
     m = {'type': 'push-pull-msg', 'nodes': nodes}
     message = json.dumps(m)
     
     (addr, port) = other
     
     uri = 'http://%s:%s/push-pull' % (addr, port)
     payload = {'msg': message}
     try:
        r = rq.get(uri, params=payload)
        logger.debug("push-pull response", r, part='gossip')
        try:
            back = json.loads(r.text)
        except ValueError, exp:
            logger.debug('ERROR CONNECTING TO %s:%s' % other, exp, part='gossip')
            return False
        pubsub.pub('manage-message', msg=back)
        #self.manage_message(back)
        return True
コード例 #3
0
ファイル: test_pubsub.py プロジェクト: pombredanne/kunai-1
    def test_pubsub(self):
        # Not registerred, so won't trigger it
        pubsub.pub("main")
        self.assert_(self.f1_raised == False)

        pubsub.sub("main", self.f1)
        pubsub.pub("main")
        self.assert_(self.f1_raised == True)

        # hard reset the bool and do with a two this time
        self.f1_raised = False
        pubsub.sub("main", self.f1)
        pubsub.sub("main", self.f2)
        pubsub.pub("main")
        self.assert_(self.f1_raised == True)
        self.assert_(self.f2_raised == True)

        # Now with params
        pubsub.sub("params", self.f3)
        pubsub.pub("params", value_set="set")
        self.assert_(self.f3_raised == True)
        self.assert_(self.f3_value == "set")
コード例 #4
0
ファイル: gossip.py プロジェクト: pombredanne/kunai-1
 def bailout_after_leave(self):
     logger.log('Bailing out in few seconds. I was put in leave state')
     time.sleep(10)
     logger.log('Exiting from a self leave message')
     # Will set self.interrupted = True to eavery thread that loop                                
     pubsub.pub('interrupt')