本文整理匯總了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()
示例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()
示例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 "
示例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()
#.........這裏部分代碼省略.........