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


Python BackdoorServer.stop方法代码示例

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

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

示例1: BackdoorPlugin

# 需要导入模块: from gevent.backdoor import BackdoorServer [as 别名]
# 或者: from gevent.backdoor.BackdoorServer import stop [as 别名]
class BackdoorPlugin(BotPlugin):
	name = 'backdoor'
	defaults = {
		'port': 1234,
	}

	def init(self):
		self.server = BackdoorServer(('localhost', self.config.port), locals={
			'clients': clients,
		})
		self.server.start()

	def cleanup(self):
		super(BackdoorPlugin, self).cleanup()
		self.server.stop()
开发者ID:ekimekim,项目名称:ekimbot,代码行数:17,代码来源:backdoor.py


示例2: Service

# 需要导入模块: from gevent.backdoor import BackdoorServer [as 别名]
# 或者: from gevent.backdoor.BackdoorServer import stop [as 别名]

#.........这里部分代码省略.........
            self.remote_services[coord] = service
        else:
            service = self.remote_services[coord]

        if on_connect is not None:
            service.add_on_connect_handler(on_connect)

        return service

    def add_timeout(self, func, plus, seconds, immediately=False):
        """Register a function to be called repeatedly.

        func (function): the function to call.
        plus (object): additional data to pass to the function.
        seconds (float): the minimum interval between successive calls
            (may be larger if a call doesn't return on time).
        immediately (bool): whether to call right off or wait also
            before the first call.

        """
        if plus is None:
            plus = {}
        func = functools.partial(func, **plus)
        if immediately:
            gevent.spawn(repeater, func, seconds)
        else:
            gevent.spawn_later(seconds, repeater, func, seconds)

    def exit(self):
        """Terminate the service at the next step.

        """
        logger.warning("%r received request to shut down.", self._my_coord)
        self.rpc_server.stop()

    def get_backdoor_path(self):
        """Return the path for a UNIX domain socket to use as backdoor.

        """
        return os.path.join(config.run_dir, "%s_%d" % (self.name, self.shard))

    @rpc_method
    def start_backdoor(self, backlog=50):
        """Start a backdoor server on a local UNIX domain socket.

        """
        backdoor_path = self.get_backdoor_path()
        try:
            os.remove(backdoor_path)
        except OSError as error:
            if error.errno != errno.ENOENT:
                raise
        else:
            logger.warning("A backdoor socket has been found and deleted.")
        mkdir(os.path.dirname(backdoor_path))
        backdoor_sock = _socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        backdoor_sock.setblocking(0)
        backdoor_sock.bind(backdoor_path)
        user = pwd.getpwnam("cmsuser")
        # We would like to also set the user to "cmsuser" but only root
        # can do that. Therefore we limit ourselves to the group.
        os.chown(backdoor_path, os.getuid(), user.pw_gid)
        os.chmod(backdoor_path, 0o770)
        backdoor_sock.listen(backlog)
        self.backdoor = BackdoorServer(backdoor_sock, locals={'service': self})
        self.backdoor.start()
开发者ID:Karl-Krauth,项目名称:cms,代码行数:70,代码来源:service.py


示例3: Service

# 需要导入模块: from gevent.backdoor import BackdoorServer [as 别名]
# 或者: from gevent.backdoor.BackdoorServer import stop [as 别名]

#.........这里部分代码省略.........
    def get_backdoor_path(self):
        """Return the path for a UNIX domain socket to use as backdoor.

        """
        return os.path.join(config.run_dir, "%s_%d" % (self.name, self.shard))

    @rpc_method
    def start_backdoor(self, backlog=50):
        """Start a backdoor server on a local UNIX domain socket.

        """
        backdoor_path = self.get_backdoor_path()
        try:
            os.remove(backdoor_path)
        except OSError as error:
            if error.errno != errno.ENOENT:
                raise
        else:
            logger.warning("A backdoor socket has been found and deleted.")
        mkdir(os.path.dirname(backdoor_path))
        backdoor_sock = _socket.socket(_socket.AF_UNIX, _socket.SOCK_STREAM)
        backdoor_sock.setblocking(0)
        backdoor_sock.bind(backdoor_path)
        user = pwd.getpwnam("cmsuser")
        # We would like to also set the user to "cmsuser" but only root
        # can do that. Therefore we limit ourselves to the group.
        os.chown(backdoor_path, os.getuid(), user.pw_gid)
        os.chmod(backdoor_path, 0o770)
        backdoor_sock.listen(backlog)
        self.backdoor = BackdoorServer(backdoor_sock, locals={'service': self})
        self.backdoor.start()

    @rpc_method
    def stop_backdoor(self):
        """Stop a backdoor server started by start_backdoor.

        """
        if self.backdoor is not None:
            self.backdoor.stop()
        backdoor_path = self.get_backdoor_path()
        try:
            os.remove(backdoor_path)
        except OSError as error:
            if error.errno != errno.ENOENT:
                raise

    def run(self):
        """Starts the main loop of the service.

        return (bool): True if successful.

        """
        try:
            self.server.start()

        # This must come before socket.error, because socket.gaierror
        # extends socket.error
        except gevent.socket.gaierror:
            logger.critical("Service %s could not listen on "
                            "specified address, because it cannot "
                            "be resolved." % (self.name))
            return False

        except gevent.socket.error as (error, unused_msg):
            if error == errno.EADDRINUSE:
                logger.critical("Listening port %s for service %s is "
开发者ID:yunmanger1,项目名称:cms,代码行数:70,代码来源:GeventLibrary.py


示例4: Dissonance

# 需要导入模块: from gevent.backdoor import BackdoorServer [as 别名]
# 或者: from gevent.backdoor.BackdoorServer import stop [as 别名]
class Dissonance(object):
    _name = None
    _web = None
    _manhole = None

    def __init__(self, config):
        opts_for = lambda name: EnvFallbackDict(name, getattr(config, '%s_opts' % name, {}))

        self._opts = EnvFallbackDict(None, getattr(config, 'dissonance_opts', {}))
        storage_class = get_storage_by_name(self._opts.get('storage', getattr(config, 'storage', 'shelve')))

        self.config = config
        self.client = Client()

        self._storage = storage_class(self, opts_for('storage'))
        self.modules = Modules(self)
        self._storage_sync_periodic = Periodic(int(self._opts.get('storage_sync_interval', 600)),
                                               self.modules._save_loaded_module_data)
        self._stop_event = Event()
        self._stop_event.set()

        self.client.events.on('message-create', self._handle_message)

    def _handle_message(self, message, client):
        if message.author == client.me:
            return

        # Schedule the handling of the message to occur during the next iteration of the event loop.
        gevent.spawn_raw(self.__handle_message, message)

    def __handle_message(self, message):
        logger.debug("Incoming message %r", message)
        start = time.time()

        message._dissonance = self
        message.targeting_client = message.content.startswith('doot, ')
        self.modules._handle_message(message)
        end = time.time()

        logger.debug("Took %.5f seconds to handle message %r", end - start, message)

    def _get_module_data(self, module):
        logger.debug("Getting module data for module %s", module.name)
        return self._storage.get_data_for_module_name(module.name)

    @property
    def name(self):
        return self.client.me.username

    @property
    def running(self):
        return not self._stop_event.is_set()

    @property
    def stopped(self):
        return not self.running

    @property
    def version(self):
        return version

    def run(self, auto_join=False):
        """
            Runs Dissonance, loading all the modules, starting the web service, and starting the adapter.

            If auto_join=True, this function will not return, and will run until dissonance stops if starting dissonance from
            outside of a greenlet.

        """
        if self.running:
            raise RuntimeError("Dissonance is already running!")

        logger.info("Starting Dissonance v%s", self.version)

        logger.info("Starting storage %s", self._storage)
        self._storage.start()

        logger.info("Loading modules")
        self.modules.load_all()

        if getattr(self.config, 'web', False) or str(self._opts.get('web', False)).upper() == 'TRUE':
            self._web = Web(self, EnvFallbackDict('web', getattr(self.config, 'web_opts', {})))
            self._web.start()

        if getattr(self.config, 'manhole', False):
            from gevent.backdoor import BackdoorServer
            manhole_opts = EnvFallbackDict('manhole', getattr(self.config, 'manhole_opts', {}))
            self._manhole = BackdoorServer((
                manhole_opts.get('listen_host', '127.0.0.1'),
                int(manhole_opts.get('listen_port', 9001))
            ), locals={
                'client': self.client
            })

            self._manhole.start()

        logger.info("Attempting to log in as %s" % self._opts['email'])
        self.client.login(self._opts['email'], self._opts['password'])
        logger.info("Starting connection to Discord")
        self.client.start()
#.........这里部分代码省略.........
开发者ID:jhgg,项目名称:dissonance,代码行数:103,代码来源:dissonance.py



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