@@ -45,6 +45,7 @@ class ProbackupApp:
45
45
46
46
def __init__ (self ,test_class :unittest .TestCase ,
47
47
pg_node ,pb_log_path ,test_env ,auto_compress_alg ,backup_dir ,probackup_path = None ):
48
+ self .process = None
48
49
self .test_class = test_class
49
50
self .pg_node = pg_node
50
51
self .pb_log_path = pb_log_path
@@ -61,7 +62,7 @@ def __init__(self, test_class: unittest.TestCase,
61
62
self .execution_time = None
62
63
63
64
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 ):
65
66
"""
66
67
Run pg_probackup
67
68
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,
118
119
logging .warning ("pg_probackup gdb suspended, waiting gdb connection on localhost:{0}" .format (gdb_port ))
119
120
120
121
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' )
126
151
end_time = time .time ()
127
152
self .execution_time = end_time - start_time
128
153