3

I am using below mentioned skills in my project for parsing CSV files in background.

Celery 3.0.22

Django 1.6.4

Python 2.7

MySQL 14.14

Distrib 5.5.38

Linux amzn1.x86_64

RabbitMQ 3.1.5

At some point time I am getting error in celery logs that "OperationalError: (2006, 'MySQL server has gone away')." and MaybeEncodingError: Error sending result: '""'. Reason: ''PicklingError("Can\'t pickle : attribute lookup msi.models.DoesNotExist failed",)''.

Please find the complete traceback below,

[2015-03-10 12:54:45,344: INFO/MainProcess] Received task: msi.tasks.UploadEventFileBackground[6572cbd7-c410-41d2-b62a-390e011b1896]
[2015-03-10 12:54:45,603: ERROR/MainProcess] Task msi.tasks.UploadEventFileBackground[6572cbd7-c410-41d2-b62a-390e011b1896] raised unexpected: "'. Reason: ''PicklingError("Can\'t pickle : attribute lookup msi.models.DoesNotExist failed",)''.>
Traceback (most recent call last):
File "/opt/msi/virtualenv/adsoft/lib/python2.7/site-packages/billiard/pool.py", line 364, in workloop
put((READY, (job, i, result, inqW_fd)))
MaybeEncodingError: Error sending result: '""'. Reason: ''PicklingError("Can\'t pickle : attribute lookup msi.models.DoesNotExist failed",)''.
[2015-03-11 00:47:32,796: INFO/MainProcess] Received task: msi.tasks.UploadDatabaseFileBackground[5f68e619-13cd-425b-998c-1ddf85fdadc2]
[2015-03-11 00:47:33,028: WARNING/Worker-1] /opt/msi/virtualenv/adsoft/lib/python2.7/site-packages/celery/app/trace.py:364: RuntimeWarning: Exception raised outside body: OperationalError(2006, 'MySQL server has gone away'):
Traceback (most recent call last):
File "/opt/msi/virtualenv/adsoft/lib/python2.7/site-packages/celery/app/trace.py", line 306, in trace_task
retval=retval, state=state)
File "/opt/msi/virtualenv/adsoft/lib/python2.7/site-packages/celery/utils/dispatch/signal.py", line 166, in send
response = receiver(signal=self, sender=sender, *named)
File "/opt/msi/projects/adsoft/msi/tasks.py", line 411, in task_postrun_handler
task_status_instance = CeleryTaskStatus.objects.get(task=task_id)
File "/opt/msi/virtualenv/adsoft/lib/python2.7/site-packages/django/db/models/manager.py", line 151, in get
return self.get_queryset().get(args, **kwargs)
File "/opt/msi/virtualenv/adsoft/lib/python2.7/site-packages/django/db/models/query.py", line 301, in get
num = len(clone)
File "/opt/msi/virtualenv/adsoft/lib/python2.7/site-packages/django/db/models/query.py", line 77, in len
self.fetch_all()
File "/opt/msi/virtualenv/adsoft/lib/python2.7/site-packages/django/db/models/query.py", line 854, in fetch_all
self._result_cache = list(self.iterator())
File "/opt/msi/virtualenv/adsoft/lib/python2.7/site-packages/django/db/models/query.py", line 220, in iterator
for row in compiler.results_iter():
File "/opt/msi/virtualenv/adsoft/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 713, in results_iter
for rows in self.execute_sql(MULTI):
File "/opt/msi/virtualenv/adsoft/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 786, in execute_sql
cursor.execute(sql, params)
File "/opt/msi/virtualenv/adsoft/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
return self.cursor.execute(sql, params)
File "/opt/msi/virtualenv/adsoft/lib/python2.7/site-packages/django/db/utils.py", line 99, in __exit
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/opt/msi/virtualenv/adsoft/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
return self.cursor.execute(sql, params)
File "/opt/msi/virtualenv/adsoft/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 124, in execute
return self.cursor.execute(query, args)
File "/opt/msi/virtualenv/adsoft/lib/python2.7/site-packages/MySQLdb/cursors.py", line 205, in execute
self.errorhandler(self, exc, value)
File "/opt/msi/virtualenv/adsoft/lib/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
OperationalError: (2006, 'MySQL server has gone away')
exc, exc_info.traceback)))
[2015-03-11 00:47:33,044: CRITICAL/MainProcess] Task msi.tasks.UploadDatabaseFileBackground[5f68e619-13cd-425b-998c-1ddf85fdadc2] INTERNAL ERROR: OperationalError(2006, 'MySQL server has gone away')
jayapal d
  • 327
  • 1
  • 6
  • 15
  • possible duplicate of [Python and Django OperationalError (2006, 'MySQL server has gone away')](http://stackoverflow.com/questions/14163429/python-and-django-operationalerror-2006-mysql-server-has-gone-away) – Alessandro Da Rugna Mar 18 '15 at 08:58
  • Nope. MySQL Is up and running. But when we use the combination of celery with Django, it happening. – jayapal d Mar 18 '15 at 10:04

1 Answers1

3

Apparently you run into a DoesNotExist Exception, which seemingly cannot be pickled (pickle is the standard serialisation method used for celery; you can also not pickle a request object for example).

For a start I would advise you to find where the error occurs.

As a rule of thumb, whenever you access the Model Manger function "get" you should encapsulate that in try-except block.

E.g.:

try:
    block = models.Block.objects.get(id=20)
except models.Block.DoesNotExist:
    pass # this object does not exist, but you script continues.
DerShodan
  • 463
  • 7
  • 16