mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-09-01 00:59:24 +00:00
Not doing so makes it hard to implement callbacks in bash and eventually can lead to the situation when two callbacks are running at the same time. In case if we failed to kill the child process we will still wait for it to finish. The same problem could happen with custom bootstrap, therefore if we happen to kill the custom bootstrap process we also kill all child subprocesses. Closes https://github.com/zalando/patroni/issues/1238
37 lines
966 B
Python
37 lines
966 B
Python
import logging
|
|
|
|
from patroni.postgresql.cancellable import CancellableExecutor
|
|
from threading import Condition, Thread
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class CallbackExecutor(CancellableExecutor, Thread):
|
|
|
|
def __init__(self):
|
|
CancellableExecutor.__init__(self)
|
|
Thread.__init__(self)
|
|
self.daemon = True
|
|
self._cmd = None
|
|
self._condition = Condition()
|
|
self.start()
|
|
|
|
def call(self, cmd):
|
|
self._kill_process()
|
|
with self._condition:
|
|
self._cmd = cmd
|
|
self._condition.notify()
|
|
|
|
def run(self):
|
|
while True:
|
|
with self._condition:
|
|
if self._cmd is None:
|
|
self._condition.wait()
|
|
cmd, self._cmd = self._cmd, None
|
|
|
|
with self._lock:
|
|
if not self._start_process(cmd, close_fds=True):
|
|
continue
|
|
self._process.wait()
|
|
self._kill_children()
|