本文整理汇总了Python中daemon.DaemonContext.terminate方法的典型用法代码示例。如果您正苦于以下问题:Python DaemonContext.terminate方法的具体用法?Python DaemonContext.terminate怎么用?Python DaemonContext.terminate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类daemon.DaemonContext
的用法示例。
在下文中一共展示了DaemonContext.terminate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _daemonize
# 需要导入模块: from daemon import DaemonContext [as 别名]
# 或者: from daemon.DaemonContext import terminate [as 别名]
def _daemonize(self):
from daemon import DaemonContext
try:
from daemon.pidfile import TimeoutPIDLockFile as PIDLockFile
except:
from daemon.pidlockfile import PIDLockFile
pidlock = PIDLockFile('/var/run/fedmsg/%s.pid' % self.name)
output = file('/var/log/fedmsg/%s.log' % self.name, 'a')
daemon = DaemonContext(pidfile=pidlock, stdout=output, stderr=output)
daemon.terminate = self._handle_signal
with daemon:
return self.run()
示例2: _daemonize
# 需要导入模块: from daemon import DaemonContext [as 别名]
# 或者: from daemon.DaemonContext import terminate [as 别名]
def _daemonize(self, func, config):
from daemon import DaemonContext
try:
from daemon.pidfile import TimeoutPIDLockFile as PIDLockFile
except:
from daemon.pidlockfile import PIDLockFile
pidlock = PIDLockFile("/var/run/fedmsg/%s.pid" % self.name)
output = file("/var/log/fedmsg/%s.log" % self.name, "a")
daemon = DaemonContext(pidfile=pidlock, stdout=output, stderr=output)
daemon.terminate = self._handle_signal
with daemon:
return func(**config)
示例3: _daemonize
# 需要导入模块: from daemon import DaemonContext [as 别名]
# 或者: from daemon.DaemonContext import terminate [as 别名]
def _daemonize(self):
import psutil
from daemon import DaemonContext
try:
from daemon.pidfile import TimeoutPIDLockFile as PIDLockFile
except:
from daemon.pidlockfile import PIDLockFile
pidlock = PIDLockFile('/var/run/fedmsg/%s.pid' % self.name)
pid = pidlock.read_pid()
if pid and not psutil.pid_exists(pid):
self.log.warn("PID file exists but with no proc: coup d'etat!")
pidlock.break_lock()
output = file('/var/log/fedmsg/%s.log' % self.name, 'a')
daemon = DaemonContext(pidfile=pidlock, stdout=output, stderr=output)
daemon.terminate = self._handle_signal
with daemon:
return self.run()
示例4: daemon
# 需要导入模块: from daemon import DaemonContext [as 别名]
# 或者: from daemon.DaemonContext import terminate [as 别名]
def daemon():
def die_in_a_fire(signum, stack):
for thread in threads:
thread.kill()
import signal
from daemon import DaemonContext
try:
from daemon.pidfile import TimeoutPIDLockFile as PIDLockFile
except:
from daemon.pidlockfile import PIDLockFile
config = appconfig("config:" + find_config_file())
#pidlock = PIDLockFile('/var/run/fedoracommunity/worker.pid')
#output = file('/var/log/fedoracommunity/worker.log', 'a')
pidlock = PIDLockFile(
config.get('cache-worker.pidfile', '/tmp/fedoracommunity-worker.pid')
)
output = file(
config.get('cache-worker.logfile', '/tmp/fedoracommunity-worker.log'),
'a')
daemon = DaemonContext(pidfile=pidlock, stdout=output, stderr=output)
daemon.terminate = die_in_a_fire
n = int(config.get('cache-worker.threads', '8'))
with daemon:
log.info("Creating %i threads" % n)
for i in range(n):
threads.append(Thread())
for thread in threads:
thread.start()
# I used to do thread.join() here, but that makes it so the
# signal_handler never gets fired. Crazy python...
while any([not thread.die for thread in threads]):
time.sleep(2)