Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit57c98b1

Browse files
author
Stepan Neretin
committed
add daemonize run binary option
1 parent726edc7 commit57c98b1

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
defrun(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+
ifdaemonize:
123+
124+
defstream_output(stream:subprocess.PIPE)->None:
125+
forlineiniter(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+
ifself.process.stdoutandself.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+
returnself.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)

[8]ページ先頭

©2009-2025 Movatter.jp