コード例 #1
0
def runner(configpath, debug_mode, import_dir, export_dir):
    try:
        #
        # Setting nice inside script so we don't get killed by OOM
        #
        os.nice(1)

        #
        # run only one instance of this script
        #
        me = singleton.SingleInstance()
        cbt = CbTaxiiFeedConverter(configpath, debug_mode, import_dir,
                                   export_dir)
        cbt.perform()
    except singleton.SingleInstanceException as e:
        logger.error("Cannot run multiple copies of this script")
        return False
    except Exception as e:
        logger.error(traceback.format_exc())
        return False
    return True
コード例 #2
0
    def start(self):
        Command.ledFlash(0, None)
        if len(sys.argv) >=2 and sys.argv[1] == 'update':
            path = sys.argv[2]
            Frame.runMainForm(True)
        self.lock = singleton.SingleInstance(os.path.join(UtilFunc.getLockDataPath(), 'popoCloudApp.lock'))
        initConsoleLog()
        thread.start_new_thread(downloadGlobalConfig, ())
        Command.showSystemInfo()
#         if UtilFunc.isPCMode():
#             self.pcServerStart()
#         else:
#             Log.info("PopoCloud Service Action!")
#             StartFunc.action(self)
        StartFunc.action(self)
        while True:
            cur_time = time.localtime()
            offset = (24 - cur_time.tm_hour) * 3600
            for service in self.services.values():
                if hasattr(service,'clean'):
                    service.clean()
            Log.clean()
            time.sleep(offset)
コード例 #3
0
ファイル: worker.py プロジェクト: sunzhongwei/mysql-queue
               self.task["task_id"]))

    def run(self):
        if self.fetch_interrupted_task():
            print "handling interrupted task"
            self.handle_task()

        while True:
            if self.fetch_new_task():
                self.handle_task()
            else:
                print "no new task, wait %s seconds to detect new task" % WAIT
                time.sleep(WAIT)


if '__main__' == __name__:
    parser = argparse.ArgumentParser()
    parser.add_argument('--worker', help='worker id, integer only.', type=int)
    args = parser.parse_args()

    if args.worker:
        print "current worker id: %s" % (args.worker, )
        lockfile = "/tmp/mysql-queue-worker-%s.lock" % args.worker
        instance = singleton.SingleInstance(lockfile)

        worker = Worker(worker_id=args.worker)
        worker.run()
    else:
        parser.print_help()
        print "invalid worker id, exit."
コード例 #4
0
#The input is a list of documents, each as one line in a file.
#the output is jason objects in one file.
import logging, sys, os, jsonpickle
import ProcessSentence, Rules, FeatureOntology
from utils import *

import singleton
me = singleton.SingleInstance()

def SentenceSegmentation(Doc):
    Sentences = [x.strip() for x in re.split("([。;!])", Doc) if x]
    #combine the sign with previous one.
    for i in range(len(Sentences)-1, -1, -1):
        if Sentences[i] in "。;!" and i>0:
            Sentences[i-1] += Sentences[i]
            del Sentences[i]

    return Sentences


if __name__ == "__main__":
    jsonpickle.set_encoder_options('json', ensure_ascii=False)
    DebugMode = False
    NoFeature = False
    level = logging.INFO
    UnitTestFileName = ''
    if len(sys.argv) > 1:
        UnitTestFileName = sys.argv[1]
        if len(sys.argv) > 2:
            command = sys.argv[2]
            if command == 'Debug':
コード例 #5
0
ファイル: main.py プロジェクト: elmit/LearningEnglish
def run():
    import singleton
    me = singleton.SingleInstance()
    os.chdir(os.path.dirname(os.path.abspath(__file__)))
    App()