本文整理汇总了Python中monitor.Monitor.rq_kill方法的典型用法代码示例。如果您正苦于以下问题:Python Monitor.rq_kill方法的具体用法?Python Monitor.rq_kill怎么用?Python Monitor.rq_kill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类monitor.Monitor
的用法示例。
在下文中一共展示了Monitor.rq_kill方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Daemon
# 需要导入模块: from monitor import Monitor [as 别名]
# 或者: from monitor.Monitor import rq_kill [as 别名]
class Daemon(Registry):
_class_id = 'Daemon'
_singleton = True
clients = {}
def __reginit__(self, daemon, sock):
self.imq = {}
self.monitor = Monitor(input_message_queue=self.imq)
self._run_server(daemon, sock)
def handle_incoming_connection(self, sock):
return sock.accept()
def service_client(self, client, addr):
server = Server(client, addr, self.host_key_file)
server.start()
return
def _run_server(self, daemon, sock):
# get host key
self.host_key_file = os.path.join(
get_config('sshproxy').get('hostkey_file'))
# set up the child killer handler
signal.signal(signal.SIGCHLD, self.monitor.kill_zombies)
try:
# set up input message queue
imq = self.imq
imq[sock] = self
# set up output message queue
omq = []
# set up error message queue
emq = []
while True:
try:
# message ready ?
try:
imr, omr, emr = select.select(imq.keys(), omq, emq, 100)
except KeyboardInterrupt:
raise
except select.error,e:
# may be caused by SIGCHLD
self.monitor.kill_zombies()
continue
except socket.error:
# may be caused by SIGCHLD
self.monitor.kill_zombies()
continue
for x in imr:
if imq[x] is self.monitor:
# consume the message
self.monitor.handle_incoming_connection(x)
continue
try:
client, addr = imq[x].handle_incoming_connection(x)
except socket.error:
continue
except Exception, e:
log.exception('ERROR: socket accept failed')
pass
raise
log.debug('Got a connection!')
pid = os.fork()
if pid == 0:
# just serve in the child
x.close()
for i in imq:
if hasattr(imq[i], 'sock'):
imq[i].sock.close()
self.monitor.clean_at_fork()
log.info("Serving %s", addr)
imq[x].service_client(client, addr)
time.sleep(0.5)
sys.exit()
client.close()
self.monitor.add_child(pid, chan=x, ip_addr=addr)
except KeyboardInterrupt:
log.info("Caught KeyboardInterrupt, exiting...")
# don't accept connections anymore
sock.close()
### FIX
self.imq.pop(0)
log.info("Signaling all child processes")
msg = ('General shutdown happening.\n'
'Please reconnect later.')
self.monitor.rq_kill(0, '', '*', msg)
# let the clients get their messages
if self.monitor.children_count():
seconds = 2
signal.signal(signal.SIGALRM, self.abort)
#.........这里部分代码省略.........