public inbox for [email protected]  
help / color / mirror / Atom feed
From: Surinder Kumar <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only
Date: Wed, 21 Sep 2016 16:18:15 +0530
Message-ID: <CAM5-9D_+dUN79tJoK35Vq2oXLybeBwVFPFKHmF5NPKg6HR_c3Q@mail.gmail.com> (raw)
List-Unsubscribe:  <mailto:[email protected]?body=unsub%20pgadmin-hackers>

Hi

While working on RM*1391 *I found another issue* 'Backup is not working on
windows".*

The reason is that the process executor which uses subprocess Popen() to
execute job fails when we pass close_fds=True and shell=False in windows.

Now we are settings close_fds=False and shell=True to fix it. These
settings are specific to windows only.

Please review the attached patch.


Thanks,
Surinder Kumar


-- 
Sent via pgadmin-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-hackers


Attachments:

  [application/octet-stream] process_executor_not_running_in_win.patch (3.0K, 3-process_executor_not_running_in_win.patch)
  download | inline diff:
diff --git a/web/pgadmin/misc/bgprocess/process_executor.py b/web/pgadmin/misc/bgprocess/process_executor.py
index d4fcd52..37127d2 100644
--- a/web/pgadmin/misc/bgprocess/process_executor.py
+++ b/web/pgadmin/misc/bgprocess/process_executor.py
@@ -35,7 +35,7 @@ import os
 import argparse
 import sqlite3
 from datetime import datetime
-from subprocess import Popen, PIPE
+import subprocess
 from threading import Thread
 import csv
 import pytz
@@ -295,10 +295,20 @@ def execute(configs):
             if args['pid'] in os.environ:
                 os.environ['PGPASSWORD'] = os.environ[args['pid']]
 
-            process = Popen(
-                command, stdout=PIPE, stderr=PIPE, stdin=PIPE,
-                shell=(os.name == 'nt'), close_fds=(os.name != 'nt')
-            )
+            if os.name == 'nt':
+                si = subprocess.STARTUPINFO()
+                si.dwFlags = subprocess.SW_HIDE
+                si.wShowWindow = 11
+                process = subprocess.Popen(
+                    command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+                    stdin=subprocess.PIPE, shell=True, close_fds=False,
+                    creationflags=0x08000000, startupinfo=si
+                )
+            else:
+                process = subprocess.Popen(
+                    command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
+                    stdin=subprocess.PIPE, shell=False, close_fds=True
+                )
             try:
                 del (os.environ['PGPASSWORD'])
             except:
diff --git a/web/pgadmin/misc/bgprocess/processes.py b/web/pgadmin/misc/bgprocess/processes.py
index f3bab26..b7ac82e 100644
--- a/web/pgadmin/misc/bgprocess/processes.py
+++ b/web/pgadmin/misc/bgprocess/processes.py
@@ -19,7 +19,7 @@ import sys
 from abc import ABCMeta, abstractproperty, abstractmethod
 from datetime import datetime
 from pickle import dumps, loads
-from subprocess import Popen, PIPE
+import subprocess
 
 import pytz
 from dateutil import parser
@@ -191,9 +191,12 @@ class BatchProcess(object):
         ]
 
         if os.name == 'nt':
-            p = Popen(
-                cmd, stdout=None, stderr=None, stdin=None, close_fds=True,
-                shell=False, creationflags=0x00000008
+            si = subprocess.STARTUPINFO()
+            si.dwFlags = subprocess.SW_HIDE
+            si.wShowWindow = 11
+            p = subprocess.Popen(
+                cmd, stdout=None, stderr=None, stdin=None, close_fds=False,
+                shell=True, creationflags=0x00000008|0x08000000, startupinfo=si
             )
         else:
             def preexec_function():
@@ -203,8 +206,8 @@ class BatchProcess(object):
                 # Explicitly ignoring signals in the child process
                 signal.signal(signal.SIGINT, signal.SIG_IGN)
 
-            p = Popen(
-                cmd, stdout=PIPE, stderr=None, stdin=None, close_fds=True,
+            p = subprocess.Popen(
+                cmd, stdout=subprocess.PIPE, stderr=None, stdin=None, close_fds=True,
                 shell=False, preexec_fn=preexec_function
             )
 


view thread (7+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only
  In-Reply-To: <CAM5-9D_+dUN79tJoK35Vq2oXLybeBwVFPFKHmF5NPKg6HR_c3Q@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox