Celery IOError:套接字已关闭

时间:2015-06-30 17:26:16

标签: python sockets flask celery

我随机收到此错误:IOError: Socket closed。听起来Web请求花费的时间太长(使用Celery任务?)并在响应完成之前终止,因此套接字关闭。但如果我同步调用任务,而不是使用.delay(),我就不会遇到这个问题。

我使用CloudAMQP作为代理,Redis作为结果存储。测试和开发服务器上的一切都完美无缺(开发和生产都使用Heroku)。

CELERY_BROKER_URL = 'amqp://urlhere'
CELERY_RESULT_BACKEND = 'redis://urlhere'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'

芹菜任务:

@celery.task()
def _track(model_type, recipient_id, event_name, properties=None):
    '''Tracks an event for a recipient'''
    properties = properties or {}
    super_properties = _get_super_properties(recipient)
    people_properties = _get_people_properties(recipient)

    all_properties = dict(super_properties)
    all_properties.update(properties)

    member = _get_member(recipient_id)

    try:
        # track
        mp.track(member.id, event_name, all_properties)
    except Exception, e:
        email_body = unicode(e)    
        mailer.notify_dev('Mixpanel error', email_body)

跟踪:

 File "/app/app/helpers/tracker.py", line 165, in track
   _track.delay(model_type, recipient.id, event_name, properties)
 File "/app/.heroku/python/lib/python2.7/site-packages/celery/app/task.py", line 453, in delay
   return self.apply_async(args, kwargs)
 File "/app/.heroku/python/lib/python2.7/site-packages/celery/app/task.py", line 559, in apply_async
   **dict(self._get_exec_options(), **options)
 File "/app/.heroku/python/lib/python2.7/site-packages/celery/app/base.py", line 353, in send_task
   reply_to=reply_to or self.oid, **options
 File "/app/.heroku/python/lib/python2.7/site-packages/celery/app/amqp.py", line 305, in publish_task
   **kwargs
 File "/app/.heroku/python/lib/python2.7/site-packages/kombu/messaging.py", line 172, in publish
   routing_key, mandatory, immediate, exchange, declare)
 File "/app/.heroku/python/lib/python2.7/site-packages/kombu/connection.py", line 457, in _ensured
   interval_max)
 File "/app/.heroku/python/lib/python2.7/site-packages/kombu/connection.py", line 369, in ensure_connection
   interval_start, interval_step, interval_max, callback)
 File "/app/.heroku/python/lib/python2.7/site-packages/kombu/utils/__init__.py", line 243, in retry_over_time
   return fun(*args, **kwargs)
 File "/app/.heroku/python/lib/python2.7/site-packages/kombu/connection.py", line 237, in connect
   return self.connection
 File "/app/.heroku/python/lib/python2.7/site-packages/kombu/connection.py", line 741, in connection
   self._connection = self._establish_connection()
 File "/app/.heroku/python/lib/python2.7/site-packages/kombu/connection.py", line 696, in _establish_connection
   conn = self.transport.establish_connection()
 File "/app/.heroku/python/lib/python2.7/site-packages/kombu/transport/pyamqp.py", line 116, in establish_connection
   conn = self.Connection(**opts)
 File "/app/.heroku/python/lib/python2.7/site-packages/amqp/connection.py", line 183, in __init__
   return self._x_open(virtual_host)
 File "/app/.heroku/python/lib/python2.7/site-packages/amqp/connection.py", line 627, in _x_open
   (10, 41),    # Connection.open_ok
 File "/app/.heroku/python/lib/python2.7/site-packages/amqp/abstract_channel.py", line 67, in wait
   self.channel_id, allowed_methods)
 File "/app/.heroku/python/lib/python2.7/site-packages/amqp/connection.py", line 240, in _wait_method
   self.method_reader.read_method()
 File "/app/.heroku/python/lib/python2.7/site-packages/amqp/method_framing.py", line 189, in read_method
   raise m
IOError: Socket closed

0 个答案:

没有答案