public inbox for [email protected]  
help / color / mirror / Atom feed
[pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only
7+ messages / 3 participants
[nested] [flat]

* [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only
@ 2016-09-21 10:48 Surinder Kumar <[email protected]>
  2016-09-22 13:05 ` Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Dave Page <[email protected]>
  0 siblings, 1 reply; 7+ messages in thread

From: Surinder Kumar @ 2016-09-21 10:48 UTC (permalink / raw)
  To: pgadmin-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
             )
 


^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only
  2016-09-21 10:48 [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Surinder Kumar <[email protected]>
@ 2016-09-22 13:05 ` Dave Page <[email protected]>
  2016-09-23 04:59   ` Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Surinder Kumar <[email protected]>
  0 siblings, 1 reply; 7+ messages in thread

From: Dave Page @ 2016-09-22 13:05 UTC (permalink / raw)
  To: Surinder Kumar <[email protected]>; +Cc: pgadmin-hackers

Can you explain what was broken exactly please? Backups work fine for
me without the patch - and whilst they also work with it, I now get an
ugly command shell window flash up which I didn't before.

On Wed, Sep 21, 2016 at 11:48 AM, Surinder Kumar
<[email protected]> wrote:
> Hi
>
> While working on RM1391 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
>



-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


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



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only
  2016-09-21 10:48 [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Surinder Kumar <[email protected]>
  2016-09-22 13:05 ` Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Dave Page <[email protected]>
@ 2016-09-23 04:59   ` Surinder Kumar <[email protected]>
  2016-09-23 08:17     ` Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Dave Page <[email protected]>
  0 siblings, 1 reply; 7+ messages in thread

From: Surinder Kumar @ 2016-09-23 04:59 UTC (permalink / raw)
  To: Dave Page <[email protected]>; +Cc: pgadmin-hackers

​Actually It doesn't broke anywhere, instead It runs successfully. On
debugging I found that it runs the subprocess.Popen() utility but it
doesn't run internally the pg_dump utitliy. On running the same command on
windows cmd prompt it works.
Then on setting parameters close_fds=False and cmd_shell=True, It works.
I ran backup in Google Chrome.


On Thu, Sep 22, 2016 at 6:35 PM, Dave Page <[email protected]> wrote:

> Can you explain what was broken exactly please? Backups work fine for
> me without the patch - and whilst they also work with it, I now get an
> ugly command shell window flash up which I didn't before.
>
> On Wed, Sep 21, 2016 at 11:48 AM, Surinder Kumar
> <[email protected]> wrote:
> > Hi
> >
> > While working on RM1391 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
> >
>
>
>
> --
> Dave Page
> Blog: http://pgsnake.blogspot.com
> Twitter: @pgsnake
>
> EnterpriseDB UK: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>


^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only
  2016-09-21 10:48 [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Surinder Kumar <[email protected]>
  2016-09-22 13:05 ` Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Dave Page <[email protected]>
  2016-09-23 04:59   ` Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Surinder Kumar <[email protected]>
@ 2016-09-23 08:17     ` Dave Page <[email protected]>
  2016-09-23 08:18       ` Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Ashesh Vashi <[email protected]>
  0 siblings, 1 reply; 7+ messages in thread

From: Dave Page @ 2016-09-23 08:17 UTC (permalink / raw)
  To: Surinder Kumar <[email protected]>; +Cc: pgadmin-hackers

On Fri, Sep 23, 2016 at 5:59 AM, Surinder Kumar
<[email protected]> wrote:
> Actually It doesn't broke anywhere, instead It runs successfully. On
> debugging I found that it runs the subprocess.Popen() utility but it doesn't
> run internally the pg_dump utitliy. On running the same command on windows
> cmd prompt it works.
> Then on setting parameters close_fds=False and cmd_shell=True, It works.
> I ran backup in Google Chrome.

It certainly runs pg_dump for me - I see the output in the monitoring
dialogue, and I get a dump file at the end.

I also use Chrome.



-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


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



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only
  2016-09-21 10:48 [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Surinder Kumar <[email protected]>
  2016-09-22 13:05 ` Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Dave Page <[email protected]>
  2016-09-23 04:59   ` Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Surinder Kumar <[email protected]>
  2016-09-23 08:17     ` Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Dave Page <[email protected]>
@ 2016-09-23 08:18       ` Ashesh Vashi <[email protected]>
  2016-09-23 08:24         ` Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Dave Page <[email protected]>
  0 siblings, 1 reply; 7+ messages in thread

From: Ashesh Vashi @ 2016-09-23 08:18 UTC (permalink / raw)
  To: Dave Page <[email protected]>; +Cc: Surinder Kumar <[email protected]>; pgadmin-hackers

On Fri, Sep 23, 2016 at 1:47 PM, Dave Page <[email protected]> wrote:

> On Fri, Sep 23, 2016 at 5:59 AM, Surinder Kumar
> <[email protected]> wrote:
> > Actually It doesn't broke anywhere, instead It runs successfully. On
> > debugging I found that it runs the subprocess.Popen() utility but it
> doesn't
> > run internally the pg_dump utitliy. On running the same command on
> windows
> > cmd prompt it works.
> > Then on setting parameters close_fds=False and cmd_shell=True, It works.
> > I ran backup in Google Chrome.
>
> It certainly runs pg_dump for me - I see the output in the monitoring
> dialogue, and I get a dump file at the end.
>
> I also use Chrome.
>
It may differ for different version of python.


--

Thanks & Regards,

Ashesh Vashi
EnterpriseDB INDIA: Enterprise PostgreSQL Company
<http://www.enterprisedb.com/;


*http://www.linkedin.com/in/asheshvashi*
<http://www.linkedin.com/in/asheshvashi;

>
>
>
> --
> Dave Page
> Blog: http://pgsnake.blogspot.com
> Twitter: @pgsnake
>
> EnterpriseDB UK: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>
>
> --
> Sent via pgadmin-hackers mailing list ([email protected])
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgadmin-hackers
>


^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only
  2016-09-21 10:48 [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Surinder Kumar <[email protected]>
  2016-09-22 13:05 ` Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Dave Page <[email protected]>
  2016-09-23 04:59   ` Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Surinder Kumar <[email protected]>
  2016-09-23 08:17     ` Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Dave Page <[email protected]>
  2016-09-23 08:18       ` Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Ashesh Vashi <[email protected]>
@ 2016-09-23 08:24         ` Dave Page <[email protected]>
  2016-09-23 08:42           ` Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Ashesh Vashi <[email protected]>
  0 siblings, 1 reply; 7+ messages in thread

From: Dave Page @ 2016-09-23 08:24 UTC (permalink / raw)
  To: Ashesh Vashi <[email protected]>; +Cc: Surinder Kumar <[email protected]>; pgadmin-hackers

On Fri, Sep 23, 2016 at 9:18 AM, Ashesh Vashi <[email protected]
> wrote:

> On Fri, Sep 23, 2016 at 1:47 PM, Dave Page <[email protected]> wrote:
>
>> On Fri, Sep 23, 2016 at 5:59 AM, Surinder Kumar
>> <[email protected]> wrote:
>> > Actually It doesn't broke anywhere, instead It runs successfully. On
>> > debugging I found that it runs the subprocess.Popen() utility but it
>> doesn't
>> > run internally the pg_dump utitliy. On running the same command on
>> windows
>> > cmd prompt it works.
>> > Then on setting parameters close_fds=False and cmd_shell=True, It works.
>> > I ran backup in Google Chrome.
>>
>> It certainly runs pg_dump for me - I see the output in the monitoring
>> dialogue, and I get a dump file at the end.
>>
>> I also use Chrome.
>>
> It may differ for different version of python.
>

Maybe. I'm using 2.7.

Either way, I don't want a command window flashing up unnecessarily.

-- 
Dave Page
Blog: http://pgsnake.blogspot.com
Twitter: @pgsnake

EnterpriseDB UK: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only
  2016-09-21 10:48 [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Surinder Kumar <[email protected]>
  2016-09-22 13:05 ` Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Dave Page <[email protected]>
  2016-09-23 04:59   ` Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Surinder Kumar <[email protected]>
  2016-09-23 08:17     ` Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Dave Page <[email protected]>
  2016-09-23 08:18       ` Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Ashesh Vashi <[email protected]>
  2016-09-23 08:24         ` Re: [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Dave Page <[email protected]>
@ 2016-09-23 08:42           ` Ashesh Vashi <[email protected]>
  0 siblings, 0 replies; 7+ messages in thread

From: Ashesh Vashi @ 2016-09-23 08:42 UTC (permalink / raw)
  To: Dave Page <[email protected]>; +Cc: Surinder Kumar <[email protected]>; pgadmin-hackers

On Fri, Sep 23, 2016 at 1:54 PM, Dave Page <[email protected]> wrote:

>
>
> On Fri, Sep 23, 2016 at 9:18 AM, Ashesh Vashi <
> [email protected]> wrote:
>
>> On Fri, Sep 23, 2016 at 1:47 PM, Dave Page <[email protected]> wrote:
>>
>>> On Fri, Sep 23, 2016 at 5:59 AM, Surinder Kumar
>>> <[email protected]> wrote:
>>> > Actually It doesn't broke anywhere, instead It runs successfully. On
>>> > debugging I found that it runs the subprocess.Popen() utility but it
>>> doesn't
>>> > run internally the pg_dump utitliy. On running the same command on
>>> windows
>>> > cmd prompt it works.
>>> > Then on setting parameters close_fds=False and cmd_shell=True, It
>>> works.
>>> > I ran backup in Google Chrome.
>>>
>>> It certainly runs pg_dump for me - I see the output in the monitoring
>>> dialogue, and I get a dump file at the end.
>>>
>>> I also use Chrome.
>>>
>> It may differ for different version of python.
>>
>
> Maybe. I'm using 2.7.
>
> Either way, I don't want a command window flashing up unnecessarily.
>
If we set the PYTHON INTERPRETER to run the background process.
i.e. BG_PYTHON_INTERPRETER=c:\Python27\pythonw.exe

We can avoid showing the flashing command window.
I came to this conclusion, because - I tried to hide them using certain
flags, but - it wasn't working well.

--

Thanks & Regards,

Ashesh Vashi
EnterpriseDB INDIA: Enterprise PostgreSQL Company
<http://www.enterprisedb.com/;


*http://www.linkedin.com/in/asheshvashi*
<http://www.linkedin.com/in/asheshvashi;

>
> --
> Dave Page
> Blog: http://pgsnake.blogspot.com
> Twitter: @pgsnake
>
> EnterpriseDB UK: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>


^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2016-09-23 08:42 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-09-21 10:48 [pgAdmin4][Patch]: Background process executor won't run(in case of Backup, restore) in Windows only Surinder Kumar <[email protected]>
2016-09-22 13:05 ` Dave Page <[email protected]>
2016-09-23 04:59   ` Surinder Kumar <[email protected]>
2016-09-23 08:17     ` Dave Page <[email protected]>
2016-09-23 08:18       ` Ashesh Vashi <[email protected]>
2016-09-23 08:24         ` Dave Page <[email protected]>
2016-09-23 08:42           ` Ashesh Vashi <[email protected]>

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