0
内のスレッドを実行しているが、私は、デーモン内のスレッドが時折シリアルポートを確認する必要があります。のpython-デーモン - Iのpython-デーモンを使用してい
context = daemon.DaemonContext(pidfile=daemon.pidfile.TimeoutPIDLockFile('/var/run/gpstemp.pid'),
uid = 0,
gid = 4,
umask = 0o002,
stdout = sys.stdout, # change these for deployment
stderr =sys.stderr, # change these for deployment
chroot_directory= None,
working_directory='/home/debian/gpstemp'
app = App()
with context:
app.run()
スレッドは、この動作します:
class App():
def __init__(self, port = 5556):
...
# Handle all those threading things
self.__sem = Lock()
self.interval = 60.0 # interval between time updates in seconds
self.worker = Thread(target = self._get_datetime_worker)
def run(self):
self.worker.start()
...
def _get_datetime_worker(self):
while not self.exit.is_set():
self._get_datetime()
self.exit.wait(self.interval)
私は、.serviceファイルを使用してsystemctlを起動および停止しています。 実行時: sudo systemctl stop myservice
戻す前に60秒待ちます。どうすればsystemctlを使ってすぐにサービス内のスレッドを削除できますか?私は、Appにコンテキストを渡すと考えられ、その後、再定義:
context.signal_map = {
signal.SIGTERM: app.shutdown,
signal.SIGHUP: app.shutdown,
}
してから行いますアプリケーションにシャットダウン方法の追加:
def shutdown(self, *args):
self.exit.set()
self.worker.join()
をしかし、コンテキストはPIDを破壊させないことと、コンテキスト右を終了しません。何かを正しく動作させるために、シャットダウン方法に何を追加する必要がありますか?
クルト