pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #14583: plpythonu : subprocess not working in function
2+ messages / 2 participants
[nested] [flat]
* BUG #14583: plpythonu : subprocess not working in function
@ 2017-03-08 17:51 paulo.nuno.leite@gmail.com
0 siblings, 1 reply; 2+ messages in thread
From: paulo.nuno.leite@gmail.com @ 2017-03-08 17:51 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
Bug reference: 14583
Logged by: Paulo B
Email address: paulo.nuno.leite@gmail.com
PostgreSQL version: 9.5.6
Operating system: Windows
Description:
I have the following function that runs a command:
CREATE OR REPLACE FUNCTION public.classify_test()
RETURNS void AS
$BODY$
import os
from subprocess import Popen, PIPE
import subprocess
import os
from subprocess import Popen, PIPE
echo=Popen(('echo', '123'), shell=True)
p = subprocess.Popen(['python.exe', '-u','test.py'], stdin = echo.stdout,
universal_newlines = True, shell = True)
$BODY$
LANGUAGE plpythonu VOLATILE
COST 100;
ALTER FUNCTION public.classify_test()
OWNER TO postgres;
if I run this fuction as select classify_test() it will not run the python
script. However, if I run it in the command line it will work. It works as
well in SublimeText2 IDE. I have been trying to find what the bug or problem
is, but had no success. I am using python2.7, I have psycopg2 installed.
Why doesn't postgresql execute the python script?
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #14583: plpythonu : subprocess not working in function
@ 2017-03-09 18:14 Kieran McCusker <kieran.mccusker@gmail.com>
parent: paulo.nuno.leite@gmail.com
0 siblings, 0 replies; 2+ messages in thread
From: Kieran McCusker @ 2017-03-09 18:14 UTC (permalink / raw)
To: paulo.nuno.leite@gmail.com; +Cc: pgsql-bugs
On 8 March 2017 at 17:51, <paulo.nuno.leite@gmail.com> wrote:
> The following bug has been logged on the website:
>
> Bug reference: 14583
> Logged by: Paulo B
> Email address: paulo.nuno.leite@gmail.com
> PostgreSQL version: 9.5.6
> Operating system: Windows
> Description:
>
> I have the following function that runs a command:
>
>
> CREATE OR REPLACE FUNCTION public.classify_test()
> RETURNS void AS
> $BODY$
> import os
> from subprocess import Popen, PIPE
> import subprocess
> import os
> from subprocess import Popen, PIPE
>
> echo=Popen(('echo', '123'), shell=True)
>
> p = subprocess.Popen(['python.exe', '-u','test.py'], stdin = echo.stdout,
> universal_newlines = True, shell = True)
>
> $BODY$
> LANGUAGE plpythonu VOLATILE
> COST 100;
> ALTER FUNCTION public.classify_test()
> OWNER TO postgres;
>
> if I run this fuction as select classify_test() it will not run the python
> script. However, if I run it in the command line it will work. It works as
> well in SublimeText2 IDE. I have been trying to find what the bug or
> problem
> is, but had no success. I am using python2.7, I have psycopg2 installed.
>
> Why doesn't postgresql execute the python script?
>
>
>
>
>
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs
Hi
I had the same problem migrating to python3. My python3 code now looks like
$BODY$
import subprocess
plpy.execute('drop server if exists fi_server_{} cascade'.format(id))
try:
subprocess.check_output(['/usr/local/bin/ogr_fdw_info',
'-s', 'fi_server_{}'.format(id),
'-t', 'import.t{0}_{1}'.format(id, worksheet),
'-d', filename,
'-w', str(worksheet)
])
except subprocess.CalledProcessError, e:
if e.returncode == 1:
plpy.execute(e.output)
return None
else:
return e.output
Hope this helps
Kieran
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2017-03-09 18:14 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-03-08 17:51 BUG #14583: plpythonu : subprocess not working in function paulo.nuno.leite@gmail.com
2017-03-09 18:14 ` Kieran McCusker <kieran.mccusker@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox