@@ -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
@@ -60,8 +61,35 @@ def __init__(self, test_class: unittest.TestCase,
6061 self .test_class .output = None
6162 self .execution_time = None
6263
64+ def form_daemon_process (self , cmdline , env ):
65+ def stream_output (stream : subprocess .PIPE ) -> None :
66+ try :
67+ for line in iter (stream .readline , '' ):
68+ print (line )
69+ self .test_class .output += line
70+ finally :
71+ stream .close ()
72+
73+ self .process = subprocess .Popen (
74+ cmdline ,
75+ stdout = subprocess .PIPE ,
76+ stderr = subprocess .PIPE ,
77+ text = True ,
78+ env = env
79+ )
80+ logging .info (f"Process started in background with PID: { self .process .pid } " )
81+
82+ if self .process .stdout and self .process .stderr :
83+ stdout_thread = threading .Thread (target = stream_output , args = (self .process .stdout ,), daemon = True )
84+ stderr_thread = threading .Thread (target = stream_output , args = (self .process .stderr ,), daemon = True )
85+
86+ stdout_thread .start ()
87+ stderr_thread .start ()
88+
89+ return self .process .pid
90+
6391 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 ):
92+ skip_log_directory = False , expect_error = False , use_backup_dir = True , daemonize = False ):
6593 """
6694 Run pg_probackup
6795 backup_dir: target directory for making backup
@@ -118,11 +146,14 @@ def run(self, command, gdb=False, old_binary=False, return_id=True, env=None,
118146 logging .warning ("pg_probackup gdb suspended, waiting gdb connection on localhost:{0}" .format (gdb_port ))
119147
120148 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' )
149+ if daemonize :
150+ return self .form_daemon_process (cmdline , env )
151+ else :
152+ self .test_class .output = subprocess .check_output (
153+ cmdline ,
154+ stderr = subprocess .STDOUT ,
155+ env = env
156+ ).decode ('utf-8' , errors = 'replace' )
126157 end_time = time .time ()
127158 self .execution_time = end_time - start_time
128159
0 commit comments