Example #1
0
def callback(ch, method, properties, body):
    #print " [x] Received %r" % (body,)
    #time.sleep(random.randint(0,3))
    #print dir(properties)
    #print properties.expiration
    #print properties.headers
    #print properties.reply_to
    #print properties.message_id
    try:
        #log("********************")
        #log(body)
        #log("********************")
        info = json.loads(body)
        detail ={}

        if MAP_INFO.has_key(method.routing_key):
            #(result,code,msg) = MAP_INFO[method.routing_key]["class"]().run(body)
            (result,code,msg,detail) = MAP_INFO[method.routing_key]["class"]().run(info)
        else:
            print "can not config method map relation:%s"%(method.routing_key)
    #MAP_INFO[]
    except Exception,e:
        #print e
        #print traceback.print_exc()
        result=False
        code = 1
        msg=traceback.print_exc()
        info ={}
        detail ={}
        log(msg)
Example #2
0
import traceback

from comm.run_config import MAP_INFO

def daemonize(noout=False):
    if noout:
        fd = open('error.txt','a')
        sys.stdout = fd
        sys.stderr = fd
        os.dup2(fd.fileno(),0)
        os.dup2(fd.fileno(),1)
        os.dup2(fd.fileno(),2)
        #fd.close()

    pid = os.fork()
    if pid >0:
        sys.exit(0)
    os.setsid()
    os.umask(0)
    pid =os.fork()
    if pid >0:
        sys.exit(0)

if __name__=='__main__':
    daemonize(True)
    for item in MAP_INFO.keys():
        for i in xrange(MAP_INFO[item].get("num",1)):
            subprocess.Popen("python receive.py "+item,shell=True)
    #for item in ["demo1","demo2","demo3"]:
    #    subprocess.Popen(run_rabbitmq_monitor(item),shell=True)
    #subprocess.Popen(run_sub(),shell=True)