Python cgi Apache os.system()
Hello :) I have installed Apache on windows... The server work well, and my python script also but when I want in my python script to run a System command like os.system(my_command) the script doesn't do anything! here the error.log [Wed Nov 08 14:19:30 2006] [error] [client 127.0.0.1] The system cannot find the drive specified.\r, referer: http://127.0.0.1/cgi-bin/extract_source.py When i run the python script manually it works! i think it's a user access probleme but i don't know how to resolve it ! please help thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Python cgi Apache os.system()
Hello thanks for your help.. it was a problem of path as you mentionned... my command was "O:\\ ccm start" and i have change it with the path of the drive O thanks a lot have a good day Tachi -- http://mail.python.org/mailman/listinfo/python-list
Apache Cgi (70007)The timeout specified has expired
Hello, When i run my python script, it works a moment and then stop with this message in the log: (70007)The timeout specified has expired: ap_content_length_filter: apr_bucket_read() failed refers to .. I think my script is too long therefore the server stop it... how can i do to run all my python script? thanks for your help -- http://mail.python.org/mailman/listinfo/python-list
spawnl and waitpid
hello, I run a python cgi script under Apache... and while the script is running i want to display a "please wait" message until the script finish. I have tried to do this but the "please wait" message appears at the script end (which is useless at this time! ) here my script: def get_ret(status): signal = status & 0xff if signal == 0: retcode = status >> 8 else: retcode = 0 return signal,retcode pidActuel = os.spawnl(os.P_NOWAIT,"c:\\python25\ \python.exe","python","Main.py") if ( get_ret(os.waitpid(pidActuel,0))[1] == 0 ): print """ END""" else: print """ please wait... """ - -- http://mail.python.org/mailman/listinfo/python-list
Re: spawnl and waitpid
i forgot ... thanks for any help :) -- http://mail.python.org/mailman/listinfo/python-list
Re: spawnl and waitpid
On 27 fév, 11:28, Thinker <[EMAIL PROTECTED]> wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > [EMAIL PROTECTED] wrote: > > hello, > > > I run a python cgi script under Apache... > > > and while the script is running i want to display a "please wait" > > message until the script finish. > > > I have tried to do this but the "please wait" message appears at > > the script end (which is useless at this time! ) > > You should flush sys.stdout after you print messages, or > the message will keep in buffer untill buffer is full or process > terminated. > > - -- > Thinker Li - [EMAIL PROTECTED] [EMAIL > PROTECTED]://heaven.branda.to/~thinker/GinGin_CGI.py > -BEGIN PGP SIGNATURE- > Version: GnuPG v1.4.6 (FreeBSD) > Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org > > iD8DBQFF5Afi1LDUVnWfY8gRAgaoAJ9fccAjo00QupE7SRFqgbmOUGZMugCgjvdH > cFoxm+jiZiIpKOfd+fHCt/M= > =9COv > -END PGP SIGNATURE- Hello thanks for answering i have flush like this but same result .. the server wait until the end... pid = os.spawnl(os.P_NOWAIT,"c:\\python25\ \python.exe","python","Main.py") sys.stdout.flush() ret = os.waitpid(pid,0) if ( ret[1] != 0): print """ wait %i """ %ret[1] sys.stdout.flush() else: print """ end %i """ %ret[1] sys.stdout.flush() -- http://mail.python.org/mailman/listinfo/python-list
Re: spawnl and waitpid
On 27 fév, 12:27, Thinker <[EMAIL PROTECTED]> wrote: > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA1 > > > > > > [EMAIL PROTECTED] wrote: > > On 27 f憝, 11:28, Thinker <[EMAIL PROTECTED]> wrote: > > [EMAIL PROTECTED] wrote: > hello, I run a python cgi script under Apache... and while > the script is running i want to display a "please wait" > message until the script finish. I have tried to do this but > the "please wait" message appears at the script end (which is > useless at this time! ) > > You should flush sys.stdout after you print messages, or the > > message will keep in buffer untill buffer is full or process > > terminated. > > > Hello > > thanks for answering i have flush like this but same result .. the > > server wait until the end... > > pid = os.spawnl(os.P_NOWAIT,"c:\\python25\ > > \python.exe","python","Main.py") sys.stdout.flush() ret = > > os.waitpid(pid,0) > > Your program will be blocked here until child process being terminated. > You should print your messages before this line. > > > if ( ret[1] != 0): print """ wait %i """ %ret[1] > > sys.stdout.flush() else: print """ end %i """ %ret[1] > > sys.stdout.flush() > > - -- > Thinker Li - [EMAIL PROTECTED] [EMAIL > PROTECTED]://heaven.branda.to/~thinker/GinGin_CGI.py > -BEGIN PGP SIGNATURE- > Version: GnuPG v1.4.6 (FreeBSD) > Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org > > iD8DBQFF5BWS1LDUVnWfY8gRAkp8AKCAcTKi/MO6sfkGBBEcMjfpH42O1wCeN14I > 0AZ83oVacK0hKik4YC/jfCA= > =3h7d > -END PGP SIGNATURE-- Masquer le texte des messages précédents - > > - Afficher le texte des messages précédents - thanks again i have tried as you said (cf bellow) and same result... is there any link which explain how a server Web read script and send the answer ? - pid = os.spawnl(os.P_NOWAIT,"c:\\python25\ \python.exe","python","Main.py") ret = os.waitpid(pid,0) print """please wait """ sys.stdout.flush() # retourne le process id if ( ret[1] != 0): print """ wait %i """ %ret[1] sys.stdout.flush() else: print """ end %i """ %ret[1] sys.stdout.flush() --- thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: spawnl and waitpid
On 27 fév, 18:54, Thinker <[EMAIL PROTECTED]> wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> [EMAIL PROTECTED] wrote:
> > i have tried as you said (cf bellow) and same result... is there
> > any link which explain how a server Web read script and send the
> > answer ?
> > -
> > pid = os.spawnl(os.P_NOWAIT,"c:\\python25\
> > \python.exe","python","Main.py")
>
> print 'please wait...'
>
> > ret = os.waitpid(pid,0)
>
> You have missed my idea.
> Since os.waitpid will be blocked, you should print your message before
> calling os.waitpid().
>
> - --
> Thinker Li - [EMAIL PROTECTED] [EMAIL
> PROTECTED]://heaven.branda.to/~thinker/GinGin_CGI.py
>
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.6 (FreeBSD)
> Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org
>
> iD8DBQFF5HA61LDUVnWfY8gRAu8sAJ4n1dogsw7RzTxH8Ke3xnNX6gXnRQCeMOKf
> /dsGHttcJc/KGpx414I7rxw=
> =E3o7
> -END PGP SIGNATURE-
hello
ha ok...
i tried this one and the browser don't write the message at once... I
have alos tried with thread and have the same result... :(
--
pid = os.spawnl(os.P_NOWAIT,"c:\\python25\
\python.exe","python","Main.py")
print 'please wait...'
sys.stdout.flush()
ret = os.waitpid(pid,0)
# retourne le process id
if ( ret[1] != 0):
print """ wait %i """ %ret[1]
sys.stdout.flush()
else:
print """ end %i """ %ret[1]
sys.stdout.flush()
-
- WITH THREAD
class AsyncLaunch(threading.Thread):
def __init__(self, infile):
threading.Thread.__init__(self)
self.infile = infile
def run(self):
os.spawnl(os.P_NOWAIT,"c:\\python25\
\python.exe","python",self.infile)
print 'Fin background'
print """please wait..."""
sys.stdout.flush()
sys.stdout.close()
## # print "fichier de log " %config.nom_log
background = AsyncLaunch('Main.py')
background.start()
##
print """The main program continues to run in foreground. wait..."""
print """ clic"""
background.join()# Wait for background task to finish
print """Main program waited until background was done."""
---
---
--
http://mail.python.org/mailman/listinfo/python-list
Re: spawnl and waitpid
On 27 fév, 19:31, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On 27 Feb 2007 05:39:51 -0800, [EMAIL PROTECTED] declaimed the
> following in comp.lang.python:
>
>
>
> > On 27 fév, 12:27, Thinker <[EMAIL PROTECTED]> wrote:
> > > -BEGIN PGP SIGNED MESSAGE-
>
>
> > > Your program will be blocked here until child process being terminated.
> > > You should print your messages before this line.
>
> > i have tried as you said (cf bellow) and same result...
>
> No, you did NOT do as was suggested (unless you misunderstood which
> line "before this" meant.
>
> > is there any link which explain how a server Web read script and send
> > the answer ?
>
> > -
> > pid = os.spawnl(os.P_NOWAIT,"c:\\python25\
> > \python.exe","python","Main.py")
> > ret = os.waitpid(pid,0)
>
> As soon as you execute os.waitpid(), your script WAITS. NOTHING
> after that point will happen until the process you are waiting on exits.
>
> > print """please wait """
> > sys.stdout.flush()
> ># retourne le process id
> > if ( ret[1] != 0):
> > print """ wait %i """ %ret[1]
> > sys.stdout.flush()
> > else:
> > print """ end %i """ %ret[1]
> > sys.stdout.flush()
>
> pid = os.spawnl(os.P_NOWAIT,
> "c:\\python25\\python.exe",
> "python",
> "Main.py")#apparently a Windows OS
> print "Please wait ..."
> sys.stdout.flush()
> ret = os.waitpid(pid, 0)
>
> if ret[1]:
> print "Non-zero exit code: %s %s" % (ret[1], ret[0])
> else:
> print "Successful exit"
> sys.stdout.flush()
>
> {I'm presuming a 0 return code means success... VMS used 1 for success
> and 0 for failure [actually, odd numbers were informational status, even
> numbers were error status]}
>
> > ---
> > thanks
>
> --
> WulfraedDennis Lee Bieber KD6MOG
> [EMAIL PROTECTED] [EMAIL PROTECTED]
> HTTP://wlfraed.home.netcom.com/
> (Bestiaria Support Staff: [EMAIL PROTECTED])
> HTTP://www.bestiaria.com/
hello
thanks a lot..
sorry for misunderstanding, my english isn't good (i'm french).
i have tried like this:
--
#! C:/Python25/python.exe
# -*- coding: cp1252 -*-
import cgitb; cgitb.enable()
import os,sys
print "Content-Type: text/html"
print
pid = os.spawnl(os.P_NOWAIT,"c:\\python25\
\python.exe","python","Main.py")
print "please wait.."
sys.stdout.flush()
ret = os.waitpid(pid,0)
# retourne le process id
if ret[1]:
print "Non-zero exit code: %s %s" % (ret[1], ret[0])
else:
print "Successful exit"
sys.stdout.flush()
and the result:
At the end of the script execution it write:
== please wait.. Successful exit
The browser doesn't let the script executing on background to write
the message at once.. it waits the end.
what happend?
--
http://mail.python.org/mailman/listinfo/python-list
Re: spawnl and waitpid
On 28 fév, 10:13, [EMAIL PROTECTED] wrote:
> On 27 fév, 19:31, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > On 27 Feb 2007 05:39:51 -0800, [EMAIL PROTECTED] declaimed the
> > following in comp.lang.python:
>
> > > On 27 fév, 12:27, Thinker <[EMAIL PROTECTED]> wrote:
> > > > -BEGIN PGP SIGNED MESSAGE-
> >
>
> > > > Your program will be blocked here until child process being terminated.
> > > > You should print your messages before this line.
>
> > > i have tried as you said (cf bellow) and same result...
>
> > No, you did NOT do as was suggested (unless you misunderstood which
> > line "before this" meant.
>
> > > is there any link which explain how a server Web read script and send
> > > the answer ?
>
> > > -
> > > pid = os.spawnl(os.P_NOWAIT,"c:\\python25\
> > > \python.exe","python","Main.py")
> > > ret = os.waitpid(pid,0)
>
> > As soon as you execute os.waitpid(), your script WAITS. NOTHING
> > after that point will happen until the process you are waiting on exits.
>
> > > print """please wait """
> > > sys.stdout.flush()
> > ># retourne le process id
> > > if ( ret[1] != 0):
> > > print """ wait %i """ %ret[1]
> > > sys.stdout.flush()
> > > else:
> > > print """ end %i """ %ret[1]
> > > sys.stdout.flush()
>
> > pid = os.spawnl(os.P_NOWAIT,
> > "c:\\python25\\python.exe",
> > "python",
> > "Main.py")#apparently a Windows
> > OS
> > print "Please wait ..."
> > sys.stdout.flush()
> > ret = os.waitpid(pid, 0)
>
> > if ret[1]:
> > print "Non-zero exit code: %s %s" % (ret[1], ret[0])
> > else:
> > print "Successful exit"
> > sys.stdout.flush()
>
> > {I'm presuming a 0 return code means success... VMS used 1 for success
> > and 0 for failure [actually, odd numbers were informational status, even
> > numbers were error status]}
>
> > > ---
> > > thanks
>
> > --
> > WulfraedDennis Lee Bieber KD6MOG
> > [EMAIL PROTECTED] [EMAIL PROTECTED]
> > HTTP://wlfraed.home.netcom.com/
> > (Bestiaria Support Staff: [EMAIL PROTECTED])
> > HTTP://www.bestiaria.com/
>
> hello
>
> thanks a lot..
>
> sorry for misunderstanding, my english isn't good (i'm french).
>
> i have tried like this:
> --
> #! C:/Python25/python.exe
> # -*- coding: cp1252 -*-
>
> import cgitb; cgitb.enable()
> import os,sys
>
> print "Content-Type: text/html"
> print
>
> pid = os.spawnl(os.P_NOWAIT,"c:\\python25\
> \python.exe","python","Main.py")
> print "please wait.."
> sys.stdout.flush()
> ret = os.waitpid(pid,0)
># retourne le process id
> if ret[1]:
> print "Non-zero exit code: %s %s" % (ret[1], ret[0])
> else:
> print "Successful exit"
> sys.stdout.flush()
>
>
> and the result:
>
> At the end of the script execution it write:
> == please wait.. Successful exit
>
> The browser doesn't let the script executing on background to write
> the message at once.. it waits the end.
>
> what happend?- Masquer le texte des messages précédents -
>
> - Afficher le texte des messages précédents -
re hello
perhaps there is a link with the script being called..
as there is a function which use stdout:
here it is
def erreur_ccm(cmd):
try:
child_stdin, child_stdout, child_stderr =os.popen3(cmd)
stderr=child_stderr.read()
stdout=child_stdout.read()
if stderr == "":
retour = stdout
else :
retour = 0
except OSError, e:
child_stdin.close()
child_stdout.close()
child_stderr.close()
return retour
--
--
http://mail.python.org/mailman/listinfo/python-list
Re: spawnl and waitpid
On 27 fév, 19:32, Thinker <[EMAIL PROTECTED]> wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> [EMAIL PROTECTED] wrote:
> > On 27 f憝, 18:54, Thinker <[EMAIL PROTECTED]> wrote:
> > hello
> > ha ok...
> > i tried this one and the browser don't write the message at once...
> > I have alos tried with thread and have the same result... :(
>
> Does child-process terminate it-self in a very short time ?
> It can be a race condition, here.
> You can try to sleep for a while in child-process to make sure parent
> being executed. Parent process may not schedule to run immediately
> after spawn. And, you can print some thing before os.spawnl() to make
> sure that message can be delivered successfully.
>
> - --
> Thinker Li - [EMAIL PROTECTED] [EMAIL
> PROTECTED]://heaven.branda.to/~thinker/GinGin_CGI.py
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.6 (FreeBSD)
> Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org
>
> iD8DBQFF5Hkp1LDUVnWfY8gRAtDdAKCKy8/ap5VJvZV14nhSCWYfLZdyYACffJ+Y
> 0sHMgyaQBmsOMwq/rxEvm1Q=
> =qjTU
> -END PGP SIGNATURE-
hello
oki, i have test a simple script that only wait...
when i tun the script without the server it write on 2 time which is
normal:
Content-Type: text/html
wait
The main program continues to run in foreground.
(((then after 5 second ))]]]
Fin background
Main program waited until background was done.
==
BUT when i call it under the server web it write after 5 second all
the message in 1 time :
===
wait The main program continues to run in foreground. Fin background
Main program waited until background was done.
===
---THE SCRIPT ---
import cgitb; cgitb.enable()
import os,sys
import threading, zipfile,time,Main
print "Content-Type: text/html"
print
print "wait"
sys.stdout.flush()
class AsyncZip(threading.Thread):
def __init__(self, infile):
threading.Thread.__init__(self)
self.infile = infile
def run(self):
time.sleep(5.0)
print 'Fin background'
background = AsyncZip('Main.py')
background.start()
print 'The main program continues to run in foreground.'
sys.stdout.flush()
background.join()# Wait for background task to finish
print 'Main program waited until background was done.'
sys.stdout.flush()
---
--
http://mail.python.org/mailman/listinfo/python-list
Re: spawnl and waitpid
On 28 fév, 11:23, [EMAIL PROTECTED] wrote:
> On 27 fév, 19:32, Thinker <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > -BEGIN PGP SIGNED MESSAGE-
> > Hash: SHA1
>
> > [EMAIL PROTECTED] wrote:
> > > On 27 f憝, 18:54, Thinker <[EMAIL PROTECTED]> wrote:
> > > hello
> > > ha ok...
> > > i tried this one and the browser don't write the message at once...
> > > I have alos tried with thread and have the same result... :(
>
> > Does child-process terminate it-self in a very short time ?
> > It can be a race condition, here.
> > You can try to sleep for a while in child-process to make sure parent
> > being executed. Parent process may not schedule to run immediately
> > after spawn. And, you can print some thing before os.spawnl() to make
> > sure that message can be delivered successfully.
>
> > - --
> > Thinker Li - [EMAIL PROTECTED] [EMAIL
> > PROTECTED]://heaven.branda.to/~thinker/GinGin_CGI.py
> > -BEGIN PGP SIGNATURE-
> > Version: GnuPG v1.4.6 (FreeBSD)
> > Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org
>
> > iD8DBQFF5Hkp1LDUVnWfY8gRAtDdAKCKy8/ap5VJvZV14nhSCWYfLZdyYACffJ+Y
> > 0sHMgyaQBmsOMwq/rxEvm1Q=
> > =qjTU
> > -END PGP SIGNATURE-
>
> hello
>
> oki, i have test a simple script that only wait...
> when i tun the script without the server it write on 2 time which is
> normal:
>
> Content-Type: text/html
> wait
> The main program continues to run in foreground.
> (((then after 5 second ))]]]
> Fin background
> Main program waited until background was done.
> ==
>
> BUT when i call it under the server web it write after 5 second all
> the message in 1 time :
> ===
> wait The main program continues to run in foreground. Fin background
> Main program waited until background was done.
> ===
>
> ---THE SCRIPT ---
> import cgitb; cgitb.enable()
> import os,sys
> import threading, zipfile,time,Main
>
> print "Content-Type: text/html"
> print
> print "wait"
> sys.stdout.flush()
>
> class AsyncZip(threading.Thread):
> def __init__(self, infile):
> threading.Thread.__init__(self)
> self.infile = infile
> def run(self):
> time.sleep(5.0)
> print 'Fin background'
>
> background = AsyncZip('Main.py')
> background.start()
> print 'The main program continues to run in foreground.'
> sys.stdout.flush()
> background.join() # Wait for background task to finish
> print 'Main program waited until background was done.'
> sys.stdout.flush()
> Masquer le
> texte des messages précédents -
>
> - Afficher le texte des messages précédents -
hello
The pb seems to be solve but no idee why as i have done lot of
changes :/ (may be the last flush or the "\n".. i'm gone
investigate..)
THANKS for helping :)
for information here the code
--
#! C:/Python25/python.exe -u
# -*- coding: cp1252 -*-
import cgitb; cgitb.enable()
import os, commands, time,Parser,config
import cgi
import sys,Function
sys.stderr = sys.stdout
print "Content-Type: text/html"
print
pid = os.spawnl(os.P_NOWAIT,"c:\\python25\
\python.exe","python","Main.py")
print "please wait...\n"
print """Le fichier de log est consultable sur fr9033256d
\execute\%s \n""" %config.nom_log
sys.stdout.flush()
ret = os.waitpid(pid,0)
if ret[1]:
print "Non-zero exit code: %s %s" % (ret[1], ret[0])
else:
print "Successful exit"
sys.stdout.flush()
--
http://mail.python.org/mailman/listinfo/python-list
