Skip to content

Commit 032f142

Browse files
author
Stepan Neretin
committed
add daemonize run binary option
1 parent 8676d48 commit 032f142

File tree

1 file changed

+31
-6
lines changed
  • testgres/plugins/pg_probackup2/pg_probackup2

1 file changed

+31
-6
lines changed

testgres/plugins/pg_probackup2/pg_probackup2/app.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class ProbackupApp:
4545

4646
def __init__(self, test_class: unittest.TestCase,
4747
pg_node, pb_log_path, test_env, auto_compress_alg, backup_dir, probackup_path=None):
48+
self.process = None
4849
self.test_class = test_class
4950
self.pg_node = pg_node
5051
self.pb_log_path = pb_log_path
@@ -61,7 +62,7 @@ def __init__(self, test_class: unittest.TestCase,
6162
self.execution_time = None
6263

6364
def run(self, command, gdb=False, old_binary=False, return_id=True, env=None,
64-
skip_log_directory=False, expect_error=False, use_backup_dir=True):
65+
skip_log_directory=False, expect_error=False, use_backup_dir=True, daemonize=False):
6566
"""
6667
Run pg_probackup
6768
backup_dir: target directory for making backup
@@ -118,11 +119,35 @@ def run(self, command, gdb=False, old_binary=False, return_id=True, env=None,
118119
logging.warning("pg_probackup gdb suspended, waiting gdb connection on localhost:{0}".format(gdb_port))
119120

120121
start_time = time.time()
121-
self.test_class.output = subprocess.check_output(
122-
cmdline,
123-
stderr=subprocess.STDOUT,
124-
env=env
125-
).decode('utf-8', errors='replace')
122+
if daemonize:
123+
124+
def stream_output(stream: subprocess.PIPE) -> None:
125+
for line in iter(stream.readline, ''):
126+
print(line)
127+
stream.close()
128+
129+
self.process = subprocess.Popen(
130+
cmdline,
131+
stdout=subprocess.PIPE,
132+
stderr=subprocess.PIPE,
133+
text=True,
134+
env=env
135+
)
136+
logging.info(f"Process started in background with PID: {self.process.pid}")
137+
138+
if self.process.stdout and self.process.stderr:
139+
stdout_thread = threading.Thread(target=stream_output, args=(self.process.stdout,))
140+
stderr_thread = threading.Thread(target=stream_output, args=(self.process.stderr,))
141+
142+
stdout_thread.start()
143+
stderr_thread.start()
144+
return self.process.pid
145+
else:
146+
self.test_class.output = subprocess.check_output(
147+
cmdline,
148+
stderr=subprocess.STDOUT,
149+
env=env
150+
).decode('utf-8', errors='replace')
126151
end_time = time.time()
127152
self.execution_time = end_time - start_time
128153

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy