<s> import logging <EOL> from copy import deepcopy <EOL> from signal import signal <EOL> from multiprocessing import cpu_count , Queue <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . conf import settings <EOL> import os <EOL> try : <EOL> import psutil <EOL> except ImportError : <EOL> psutil = None <EOL> class Conf ( object ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> conf = settings . Q_CLUSTER <EOL> except AttributeError : <EOL> conf = { } <EOL> REDIS = conf . get ( '<STR_LIT>' , { } ) <EOL> DJANGO_REDIS = conf . get ( '<STR_LIT>' , None ) <EOL> DISQUE_NODES = conf . get ( '<STR_LIT>' , None ) <EOL> DISQUE_AUTH = conf . get ( '<STR_LIT>' , None ) <EOL> DISQUE_FASTACK = conf . get ( '<STR_LIT>' , False ) <EOL> IRON_MQ = conf . get ( '<STR_LIT>' , None ) <EOL> SQS = conf . get ( '<STR_LIT>' , None ) <EOL> ORM = conf . get ( '<STR_LIT>' , None ) <EOL> BROKER_CLASS = conf . get ( '<STR_LIT>' , None ) <EOL> POLL = conf . get ( '<STR_LIT>' , <NUM_LIT> ) <EOL> MONGO = conf . get ( '<STR_LIT>' , None ) <EOL> MONGO_DB = conf . get ( '<STR_LIT>' , None ) <EOL> PREFIX = conf . get ( '<STR_LIT:name>' , '<STR_LIT:default>' ) <EOL> LOG_LEVEL = conf . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> SAVE_LIMIT = conf . get ( '<STR_LIT>' , <NUM_LIT> ) <EOL> SCHEDULER = conf . get ( '<STR_LIT>' , True ) <EOL> WORKERS = conf . get ( '<STR_LIT>' , False ) <EOL> if not WORKERS : <EOL> try : <EOL> WORKERS = cpu_count ( ) <EOL> except NotImplementedError : <EOL> if psutil : <EOL> WORKERS = psutil . cpu_count ( ) or <NUM_LIT:4> <EOL> else : <EOL> WORKERS = <NUM_LIT:4> <EOL> QUEUE_LIMIT = conf . get ( '<STR_LIT>' , int ( WORKERS ) ** <NUM_LIT:2> ) <EOL> COMPRESSED = conf . get ( '<STR_LIT>' , False ) <EOL> RECYCLE = conf . get ( '<STR_LIT>' , <NUM_LIT> ) <EOL> TIMEOUT = conf . get ( '<STR_LIT>' , None ) <EOL> RETRY = conf . get ( '<STR_LIT>' , <NUM_LIT> ) <EOL> BULK = conf . get ( '<STR_LIT>' , <NUM_LIT:1> ) <EOL> LABEL = conf . get ( '<STR_LIT:label>' , '<STR_LIT>' ) <EOL> CPU_AFFINITY = conf . get ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> SYNC = conf . get ( '<STR_LIT>' , False ) <EOL> CACHE = conf . get ( '<STR_LIT>' , '<STR_LIT:default>' ) <EOL> CACHED = conf . get ( '<STR_LIT>' , False ) <EOL> CATCH_UP = conf . get ( '<STR_LIT>' , True ) <EOL> SECRET_KEY = settings . SECRET_KEY <EOL> Q_STAT = '<STR_LIT>' . format ( PREFIX ) <EOL> ROLLBAR = conf . get ( '<STR_LIT>' , { } ) <EOL> try : <EOL> QSIZE = Queue ( ) . qsize ( ) == <NUM_LIT:0> <EOL> except NotImplementedError : <EOL> QSIZE = False <EOL> SIGNAL_NAMES = dict ( ( getattr ( signal , n ) , n ) for n in dir ( signal ) if n . startswith ( '<STR_LIT>' ) and '<STR_LIT:_>' not in n ) <EOL> STARTING = _ ( '<STR_LIT>' ) <EOL> WORKING = _ ( '<STR_LIT>' ) <EOL> IDLE = _ ( "<STR_LIT>" ) <EOL> STOPPED = _ ( '<STR_LIT>' ) <EOL> STOPPING = _ ( '<STR_LIT>' ) <EOL> TESTING = conf . get ( '<STR_LIT>' , False ) <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> if not logger . handlers : <EOL> logger . setLevel ( level = getattr ( logging , Conf . LOG_LEVEL ) ) <EOL> logger . propagate = False <EOL> formatter = logging . Formatter ( fmt = '<STR_LIT>' , <EOL> datefmt = '<STR_LIT>' ) <EOL> handler = logging . StreamHandler ( ) <EOL> handler . setFormatter ( formatter ) <EOL> logger . addHandler ( handler ) <EOL> if Conf . ROLLBAR : <EOL> rollbar_conf = deepcopy ( Conf . ROLLBAR ) <EOL> try : <EOL> import rollbar <EOL> rollbar . init ( rollbar_conf . pop ( '<STR_LIT>' ) , environment = rollbar_conf . pop ( '<STR_LIT>' ) , ** rollbar_conf ) <EOL> except ImportError : <EOL> rollbar = None <EOL> else : <EOL> rollbar = None <EOL> def get_ppid ( ) : <EOL> if hasattr ( os , '<STR_LIT>' ) : <EOL> return os . getppid ( ) <EOL> elif psutil : <EOL> return psutil . Process ( os . getpid ( ) ) . ppid ( ) <EOL> else : <EOL> raise OSError ( '<STR_LIT>' ) </s>
