当前位置: 首页>>代码示例>>Python>>正文


Python Process.stop方法代码示例

本文整理汇总了Python中multiprocessing.Process.stop方法的典型用法代码示例。如果您正苦于以下问题:Python Process.stop方法的具体用法?Python Process.stop怎么用?Python Process.stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在multiprocessing.Process的用法示例。


在下文中一共展示了Process.stop方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MQTTClientProcess

# 需要导入模块: from multiprocessing import Process [as 别名]
# 或者: from multiprocessing.Process import stop [as 别名]
class MQTTClientProcess():

    def __init__(self, clientid, broker="localhost", port=1884):
        self.queue = Queue()
        self.clientid = clientid
        self.broker = broker
        self.port = port
        self.started = False
        self.process = Process(target=self.startProcess, args=(self.queue, self.clientid, broker, port,))

    def send(self, channel, value):
        self.queue.put((channel, value))

    def start(self):
        self.process.start()
        self.started = True

    def stop(self):
        self.process.stop()
        self.started = False

    def startProcess(self, queue, clientid, host, port):
        setproctitle("MQTT Client")
        print("Connecting to broker")
        print("Host: %s" % host)
        print("Port: %s" % port)
        mqttc = paho.Client(clientid)
        mqttc.connect(host, port=port, keepalive=60)
        print("Connected Successfully.\n")
        while True:
            data = queue.get(block=True)
            print("Sending Data.\n")
            print(data[0])
            mqttc.publish("{}/{}".format(clientid, data[0]), data[1])
开发者ID:qutm2m2014,项目名称:client,代码行数:36,代码来源:mqttclient.py

示例2: Reloader

# 需要导入模块: from multiprocessing import Process [as 别名]
# 或者: from multiprocessing.Process import stop [as 别名]
class Reloader(object):

    """Reload service when files change"""

    def __init__(self, sig='SIGHUP', files=[]):
        if not files:
            raise Exception('No file to watch for reload')

        self.log = Logs().log
        self.proc = None
        self._files = files
        sig_attr = getattr(signal, sig)
        try:
            assert int(sig_attr)
        except:
            raise Exception('Wrong signal provided for reload')
        self.observer = Observer()
        rel = Reload(sig=sig_attr, reloader=self)
        for dir in self.dirs:
            self.log.debug('Registering watcher for {dir}'.format(dir=dir))
            self.observer.schedule(rel, dir, recursive=False)

    def _get_files(self):
        """Return iterator of tuples (path, file)"""
        for f in self._files:
            for m in glob.iglob(f):
                if os.path.isdir(m):
                    yield (m, m)
                yield (os.path.dirname(m), m)
            if os.path.isdir(f):
                yield (f, f)
            yield (os.path.dirname(f), f)

    @property
    def files(self):
        """Return list of watched files"""
        return list(set([files[1] for files in self._get_files()]))

    @property
    def dirs(self):
        """Return list of watched directories"""
        return list(set([files[0] for files in self._get_files()]))

    def run(self, ret=False):
        while True:
            self.observer.start()
            if ret:
                return self.observer
            self.observer.join()

    def run_in_process(self):
        self.proc = Process(target=self.run)
        self.proc.start()

    def stop(self):
        if self.proc:
            self.proc.stop()
        else:
            self.observer.stop()
开发者ID:cmehay,项目名称:pyentrypoint,代码行数:61,代码来源:reloader.py

示例3: execute

# 需要导入模块: from multiprocessing import Process [as 别名]
# 或者: from multiprocessing.Process import stop [as 别名]
def execute(module,
            topology_module = None,
            topology=default_topology,
            function=default_function,
            args=default_args,
            cli=default_cli,
            timeout=default_timeout,
            nodes=default_nodes,
            nox_path=default_nox_path,
            verbose=default_verbose,
            experiment_mode=default_experiment_mode):

    nodes = int(nodes)
    topology_module = module + "_topo" if topology_module is None else topology_module

    dirs = fetch_subdirs()
    setup_env(module, topology_module, function, args, topology, dirs, experiment_mode, nodes)
    import_directories(dirs)

    q = Queue()
    listener = Listener(signal_address)
    wait = Process(target=receive_signal, args=(listener,q))
    wait.daemon = True
    wait.start()

    # if experiment_mode:
    #     update_application = get_function_by_name(module, function)
    #     initial_topology = get_function_by_name(topology_module, topology)
    #     setup = get_function_by_name("update_lib", "setup")
    #     inst = DummyComponent(args, update_application, setup, initial_topology)
    #     os._exit(0)
        
    if experiment_mode:
        # yappi.start()
        nox = Process(target=run_nox)
        nox = NOX("c0", "UpdateApp")
        nox.start()
        lg.setLogLevel('output')        
        output("*** Application started ***\n")
        wait.join(timeout)
        msg = ""
        status = ""
        if wait.is_alive():
            status = "killed"
            wait.terminate()
        else:
            status = "finished"
            msg = q.get()
        # yappi.stop()
        # stats = string.join([str(stat) for stat in yappi.get_stats(yappi.SORTTYPE_TTOTAL)],"\n")
        output("*** Application %s ***\n%s" % (status, msg))
        # output("*** Stats %s " % (stats))
        if verbose:
            output("\n*** Controller output: ***\n" + getControllerOutput() + "\n")
        nox.stop()
        os._exit(0)
    # elif nox_only:
    #     nox_command = os.path.expanduser(nox_path)
    #     nox_dir = os.path.dirname(nox_command)
    #     os.chdir(nox_dir)
    #     if verbose:
    #         nox_command += " -v"
 
    #     command = "%s -i ptcp:6633 %s" % (nox_command,"UpdateApp")
    #     os.system(command)        
    #     wait.join()
    #     os._exit(0)

    else:
        global mininet
        topo = get_function_by_name(topology_module, topology)(nodes).mininet_topo()
        mininet = Mininet( topo=topo, switch=UserSwitch,
                           controller=lambda name: NOX(name, "UpdateApp"),
                           xterms=False, autoSetMacs=True, autoStaticArp=True )
        mininet.start()
        lg.setLogLevel('output')
        output("*** Mininet Up ***\n")
        output("*** Application started ***\n")
        if cli:
            CLI(mininet)
        wait.join(timeout)
        msg = ""
        status = ""
        if wait.is_alive():
            status = "killed"
            listener.close()
            wait.terminate()
        else:
            status = "finished"
            msg = q.get()
        output("*** Application %s ***\n%s" % (status, msg))
        if verbose:
            output("*** Controller output: ***\n" + getControllerOutput() + "\n")
        mininet.stop()
        output("*** Mininet Down ***\n")
        os._exit(0)
开发者ID:XianliangJ,项目名称:collections,代码行数:98,代码来源:run.py

示例4: Choco

# 需要导入模块: from multiprocessing import Process [as 别名]
# 或者: from multiprocessing.Process import stop [as 别名]
class Choco(object):
    def __init__(self, config):
        self.config = config
        self.queue = Queue(10000)
        self.count = 0
        self.pool = [Thread(target=self.start) for i in range(config.THREAD_COUNT)]
        self.working_count = Value(c_int)
        self.working_count_lock = Lock()
        if os.name is 'nt':
            self.watch_process = Thread(target=self.watch)
            self.ping_process = Thread(target=self.auto_ping)
        else:
            self.watch_process = Process(target=self.watch)
            self.ping_process = Process(target=self.auto_ping)
        self.exit = Value(c_bool)
        self.kakao = None

        redis_pool = redis.ConnectionPool(host=config.REDIS_HOST,
            port=config.REDIS_PORT,
            db=config.REDIS_DB,
            password=config.REDIS_PASSWORD)
        self.cache = ChocoCache.adapter = redis.Redis(connection_pool=redis_pool)
        self.module = Endpoint()
        self.module.set_prefix(config.COMMAND_PREFIX)

        self.cli = ChocoCLI(self)

        auth_mail = self.cache.hget('choco_auth', 'mail')
        auth_pass = self.cache.hget('choco_auth', 'password')
        auth_client = self.cache.hget('choco_auth', 'client')
        auth_x_vc = self.cache.hget('choco_auth', 'x_vc')
        if self.cache.hexists('choco_auth', 'uuid_base64'):
            auth_uuid = self.cache.hget('choco_auth', 'uuid_base64')
        else:
            auth_uuid = base64.b64encode(self.cache.hget('choco_auth', 'uuid'))

        if not auth_client:
            print >> sys.stderr, "Authenticate failed: client name not found\n" + \
                "Please check config.py and set 'choco_auth' to redis server"
            sys.exit(1)
        elif not auth_uuid:
            print >> sys.stderr, "Authenticate failed: uuid not found\n" + \
                "Please check config.py and set 'choco_auth' to redis server"
            sys.exit(1)

        self.load_module()
        if self.auth_kakao(auth_mail, auth_pass, auth_client, auth_uuid, auth_x_vc):
            print >> sys.stdout, 'Successfully connected to KakaoTalk server'

    def load_module(self):
        from modules import init_module, module_loader
        init_module(self, self.module)
        module_loader(home, self.config)

    def auth_kakao(self, mail, password, client, uuid, x_vc):
        user_session = self.cache.hget('choco_session', 'key')
        user_id = self.cache.hget('choco_session', 'id')

        if not user_session or not user_id:
            if not mail:
                print >> sys.stderr, "Authenticate failed: email address not found\n" + \
                    "Please check config.py and set 'choco_auth' to redis server"
                sys.exit(1)
            elif not password:
                print >> sys.stderr, "Authenticate failed: password not found\n" + \
                    "Please check config.py and set 'choco_auth' to redis server"
                sys.exit(1)
            elif not x_vc:
                print >> sys.stderr, "Authenticate failed: X-VC token not found\n" + \
                    "Please check config.py and set 'choco_auth' to redis server"
                sys.exit(1)

            self.kakao = kakaotalk(debug=self.config.DEBUG)
            auth_result = self.kakao.auth(mail, password, client, uuid, x_vc)
            if not auth_result:
                print >> sys.stderr, "KakaoTalk auth failed"
                sys.exit(1)
            else:
                login_result = self.kakao.login()
                if not login_result:
                    print >> sys.stderr, "KakaoTalk login failed"
                    sys.exit(1)
                else:
                    self.cache.hset('choco_session', 'key', self.kakao.session_key)
                    self.cache.hset('choco_session', 'id', self.kakao.user_id)
        else:
            self.kakao = kakaotalk(user_session, uuid, user_id,
                debug=self.config.DEBUG)
            login_result = self.kakao.login()
            if not login_result:
                print >> sys.stderr, "KakaoTalk login failed"
                sys.exit(1)

        return True

    def reload_kakao(self):
        print >> sys.stdout, 'Trying to reconnect..'
        self.ping_process.stop()
        for p in self.pool:
            p.stop()
#.........这里部分代码省略.........
开发者ID:askagirl,项目名称:choco,代码行数:103,代码来源:__init__.py


注:本文中的multiprocessing.Process.stop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。