Forums

strange error with django/python 3 and mysql database

Hi,

I've developped a Django application with python 3 for online signal processing and analysis: www.sp4mass.com

There is no problem with the app with the sqlite default database. However, when I switch to a mysql database, the site runs fine during 5 minutes and then the server returns a 500 error after the next request. Specifically, the server log indicates the following error:

2014-05-01 08:00:00 Thu May  1 08:00:00 2014 - SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected)     on request /signal/ (ip 10.86.247.9) !!!

I need to restart the server tosolve this issue. However, the same error occurs after 5 minutes. My settings are

DATABASES = {
'default': {
    'NAME': xxx,
    'ENGINE': 'mysql.connector.django',
    'USER': xxx,
    'PASSWORD': xxx,
}

Is it a database error ?

If the 5 mins is approximately accurate and not just a placeholder for "some minutes" then it's suspiciously close to the time limit we give to web apps to deal with a request before we assume they've died and stop them. Do you have pages that take a long time to produce? Perhaps switching to MySQL has caused your requests to take a little longer and bumped them over the limit (either because you're doing something that is faster in SQLite or because you have more data in MySQL)

Thank you for your answer.

My problem occurs after "some minutes" of inactivity. I don't think that this problem is due to the page creation because the page content is really small. Furthermore, my mysql database is almost empty.

Do you have the correct version of the MySQL connector installed? Try:

pip3 show mysql-connector-python

it should show that you have version 1.1.6 installed. If it doesn't, there are instructions here

Thank's,

I've already performed the instructions provided in your link. This problem is really strange:

Using sqlite: - syncdb perform well with django setting DEBUG=TRUE or DEBUG=FALSE.

Using MySQL: - syncdb does not work with django setting DEBUG=TRUE. Specifically, the error.log file contains the following error

Traceback (most recent call last):
2014-05-01 21:52:38,793 :  File "/usr/local/lib/python3.3/dist-packages/django/core/urlresolvers.py", line 339, in urlconf_module
2014-05-01 21:52:38,793 :    return self._urlconf_module
2014-05-01 21:52:38,793 :AttributeError: 'RegexURLResolver' object has no attribute '_urlconf_module'
  • syncdb perform well with django setting DEBUG=FALSE. However, the SIGPIPE error occurs after approximatively 5 minutes.

One possibility is that it's the database connection being closed after a period of inactivity. Normally Django handles that kind of thing for you -- it makes sure that the DB connection you have is valid and properly connected (reconnecting if necessary) before you go into any view.

But perhaps you're accessing the database from outside views? Perhaps in a long-running manage.py command or something like that?