work-around for (2006, 'MySQL server has gone away')? <p>This question is my exact issue</p> <p><a href="http://stackoverflow.com/questions/7835272/django-operationalerror-2006-mysql-server-has-gone-away">Django - OperationalError: (2006, &#39;MySQL server has gone away&#39;)</a></p> <p>An aparent work-around to this otherwise unresolved problem is to increase the <a href="http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_wait_timeout" rel="nofollow">wait_timeout</a> for the execution</p> <p><strong>Background</strong></p> <p>I have a celery task which runs at a specific time once a day. Initially it was working fine but from last week i have started getting :</p> <blockquote> <p>Exception_ocoured_: (2013, 'Lost connection to MySQL server during query')</p> </blockquote> <p>This celery task simply fetches some details from db, max of 4000 rows and mails to the end user.</p> <p><strong>Question :</strong></p> <p>Is there any way to increase this timeout <em>only for the specific celery task</em> which is facing this issue in django environment, as i don't want to disturb the native setup?</p> <p>I am looking for a <em>django</em>ish solution whose lifetime is only as long as this celery task executes.</p> <p>For eg :</p> <pre><code>@task def doSomething(): try: set_timeout_for_mysql = 20000 # &lt;== main agenda for this question # OR ping_resp = somehow_test_mysql_con() while(ping_resp == False): keep trying to connect or create new connection # do_operations except Exception, e: # log exception </code></pre> <p><strong>Spec :</strong></p> <pre><code>In [18]: django.VERSION Out[18]: (1, 7, 7, 'final', 0) </code></pre> <p>and</p> <pre><code>django-celery==3.0.21 </code></pre> <p><strong>PS :</strong> Any other workaround will do if someone has resolved this without disturbing the core setup!!!</p>