Python psycopg2 + mod_wsgi: connection is very slow and automatically close - python

I have made a python ladon webservice and I run is on Ubuntu with Apache2 and mod_wsgi. (I use Python 2.6).
The webservice connect to a postgreSQL database with psycopg2 python module.
My problem is that the psycopg2.connection is closed (or destroyed) automatically after a little time (after about 1 or 2 minutes).
The other hand if I run the server with
ladon2.6ctl testserve
command (http://ladonize.org/index.php/Python_Configuration)
than the server is working and the connection is not closed automatically.
I can't understand why the connection is closed with apache+mod_wsgi and in this case the webserver is very slowly.
Can anyone help me?

If you are using mod_wsgi in embedded moe, especially with preform MPM for Apache, then likely that Apache is killing off the idle processes. Try using mod_wsgi daemon mode, which keeps process persistent and see if it makes a difference.

Related

Is there a way run a python script on another server?

I have a Djnago web application on IIS 6 on one server. Is there a way that from this website I call another python script that is on another server in such a way that that script just run itself there?
Calling or Runnig that script in the usual way as internet says, is not working.
I always get the error of os.getcwd() and it also doesn't allow to change that directory.
I just want to run that python script there on that server from this server.
Can anyone help?
Normally, I would recommend using a framework like fabric or winrm if you want to run a python script on another server. Those frameworks use ssh or windows remoting functionality, respectively, to allow a python program to execute other commands (including python scripts) on other systems. If the target machine is a windows machine, be forewarned that you can run into all sorts of UAC issues doing normal operations.

Graceful reload of python tornado server [duplicate]

This question already has answers here:
Is there a way to deploy new code with Tornado/Python without restarting the server?
(5 answers)
Closed 7 years ago.
I have an HTTP server created by the Tornado framework. I need to update/reload this server without any connection lost and shutdown.
I have no idea how to do it.
Could you get me any clue?
Easy way, do it with nginx.
Start a latest tornado server.
Redirect all new connections to the new tornado server.(Change nginx configure file and reload with nginx -s reload)
Tell the old tornado server shutdown itself if all connections are closed.
Hard way
If you want to change your server on the fly, maybe you could find a way by reading nginx's source code, figure out how nginx -s reload works, but I think you need to do lots of work.

script timed out before returning headers openshift

I have a python application (webservice) hosted in Openshift but, a few days ago, the app don't work anymore. The log points to "[error] script timed out before returning headers" and I can't solve this.
Someone can help me?
The solution was remove the cartridge and install Python 2.6
Please log in to your openshift account and check whether your application and cartridges are up and running.
From the mod_wsgi FAQ:
Q: Why am I seeing the error message 'premature end of script headers'
in the Apache error logs.
A: If using daemon mode, this is a symptom of the mod_wsgi daemon
process crashing when handling a request. You would probably also see
the message 'segmentation fault'. See answer for question about
'segmentation fault' above.
This error message can also occur where you haven't configured Apache
correctly and your WSGI script file is being executed as a CGI script
instead.
It could also be possibly due to the application code hanging. This can be due to the use of third party Python modules which have a C extension component which does not work in Python sub interpreters.
http://code.google.com/p/modwsgi/wiki/ApplicationIssues#Python_Simplified_GIL_State_API
Unfortunately OpenShift has a less than ideal mod_wsgi configuration and no ready ability to override the configuration nor the start up of Apache itself. At least not unless that have made significant changes since the last time I looked.

SQlite3 locking windows

I am noticing locking (OperationalError) when using the SQLite 3.7 for python application . I am using SQLalchemy for ORM.This issue occurs on windows. I using the DB on the same machine as the application.
It seems to be working fine on ubuntu. Wondering what might be the issue? Did some older version of sqlite had this issue that got fixed?
Some thoughts :
-There is locking issue with windows NFS for SQLlite , but since i am using local filesystem this possibility is discarded.
Can a antivirus running on the machine cause a lock , since it reads file as and when updated.
The lock on the database is never released ( i waited for like 5 min , while accessing the DB via command line). This make me think whether some hanging process was holding on to lock or the process got killed. But seems that was not the case as the only process(python bottle server) that was accessing the DB was running. It is running under single process Apache.
The way locking happens with SQLite is documented at http://www.sqlite.org/lockingv3.html - read it. On Windows you can use Sysinternal's Process Monitor to monitor who is accessing the file which will zero down on the culprit.

apache server with mod_wsgi + python as backend, how can i be able to notified my connection status?

i'm trying to build a web server using apache as the http server, mod_wsgi + python as the logic handler, the server was supposed to handler long request without returning, meaning i want to keep writing stuff into this request.
the problem is, when the link is broken, the socket is in a CLOSE_WAIT status, apache will NOT notify my python program, which means, i have to write something to get an exception, says the link is broken, but those messages were lost and can't be restored.
i tried to get the socket status before writing through /proc/net/tcp, but it could not prevent a quick connect/break connection.
anybody has any ideas, please help, very much thanks in advance!
You cant. It is a limitation of the API defined by the WSGI specification. So, nothing to do with Apache or mod_wsgi really as you will have the same issue with any WSGI server if you follow the WSGI specification.
If you search through the mod_wsgi mailing list on Google Groups you will find a number of discussions about this sort of problem in the past.

Categories