<h1 dir="auto">Checklist</h1>

<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have verified that the issue exists against the <code class="notranslate">master</code> branch of Celery.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> This has already been asked to the <a href="https://groups.google.com/forum/#!forum/celery-users" rel="nofollow">discussion group</a> first.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have read the relevant section in the<br>
<a href="http://docs.celeryproject.org/en/latest/contributing.html#other-bugs" rel="nofollow">contribution guide</a><br>
on reporting bugs.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/issues?q=is%3Aissue+label%3A%22Issue+Type%3A+Bug+Report%22+-label%3A%22Category%3A+Documentation%22">issues list</a><br>
for similar or identical bug reports.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/pulls?q=is%3Apr+label%3A%22PR+Type%3A+Bugfix%22+-label%3A%22Category%3A+Documentation%22">pull requests list</a><br>
for existing proposed fixes.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/celery/celery/commits/master">commit log</a><br>
to find out if the bug was already fixed in the master branch.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have included all related issues and possible duplicate issues<br>
in this issue (If there are none, check this box anyway).</li>
</ul>
<h4 dir="auto">Related Issues</h4>
<p dir="auto"><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="673404521" data-permission-text="Title is private" data-url="https://github.com/celery/py-amqp/issues/330" data-hovercard-type="issue" data-hovercard-url="/celery/py-amqp/issues/330/hovercard" href="https://github.com/celery/py-amqp/issues/330">celery/py-amqp#330</a></p>
<h4 dir="auto">Possible Duplicates</h4>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="25393727" data-permission-text="Title is private" data-url="https://github.com/celery/celery/issues/1779" data-hovercard-type="issue" data-hovercard-url="/celery/celery/issues/1779/hovercard" href="https://github.com/celery/celery/issues/1779">#1779</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="34744361" data-permission-text="Title is private" data-url="https://github.com/celery/celery/issues/2066" data-hovercard-type="issue" data-hovercard-url="/celery/celery/issues/2066/hovercard" href="https://github.com/celery/celery/issues/2066">#2066</a></li>
</ul>
<p dir="auto"></p>

<h2 dir="auto">Minimally Reproducible Test Case</h2>
<p dir="auto">See <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="673404521" data-permission-text="Title is private" data-url="https://github.com/celery/py-amqp/issues/330" data-hovercard-type="issue" data-hovercard-url="/celery/py-amqp/issues/330/hovercard?comment_id=706148277&amp;comment_type=issue_comment" href="https://github.com/celery/py-amqp/issues/330#issuecomment-706148277">celery/py-amqp#330 (comment)</a></p>
<h1 dir="auto">Expected Behavior</h1>
<p dir="auto">Celery should be able to be called from multiple threads - e.g. from gunicorn container</p>
<h1 dir="auto">Actual Behavior</h1>
<p dir="auto">Due race conditions inside backends, Celery serving data is stalled or it returns "0x01 while expecting 0xce" errors, or others (depends on backend) - see <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="673404521" data-permission-text="Title is private" data-url="https://github.com/celery/py-amqp/issues/330" data-hovercard-type="issue" data-hovercard-url="/celery/py-amqp/issues/330/hovercard" href="https://github.com/celery/py-amqp/issues/330">celery/py-amqp#330</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="25393727" data-permission-text="Title is private" data-url="https://github.com/celery/celery/issues/1779" data-hovercard-type="issue" data-hovercard-url="/celery/celery/issues/1779/hovercard" href="https://github.com/celery/celery/issues/1779">#1779</a>, <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="34744361" data-permission-text="Title is private" data-url="https://github.com/celery/celery/issues/2066" data-hovercard-type="issue" data-hovercard-url="/celery/celery/issues/2066/hovercard" href="https://github.com/celery/celery/issues/2066">#2066</a></p>
<h1 dir="auto">Details</h1>
<p dir="auto">The issue is caused by sharing resources between threads. This issue can be broken into 2 separate sub-issues:</p>
<ol dir="auto">
<li>Underlying Connection is shared between threads:<br>
When <code class="notranslate">rpc</code> backend is used, kombu/py-amqp backend is used. This backend supports <strong>only one connection per thread</strong>. Unfortunately since using single backend object in all threads, all threads shares single connections causing "0x01 while expecting 0xce" errors or other creashes:<br>
<div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/celery/celery/blob/05da357502a109c05b35392391299d75d181ccab/celery/app/base.py#L1166-L1167">celery/celery/app/base.py</a>
    </p>
    <p class="mb-0 color-fg-muted">
        Lines 1166 to 1167
      in
      <a data-pjax="true" class="commit-tease-sha" href="/celery/celery/commit/05da357502a109c05b35392391299d75d181ccab">05da357</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L1166" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="1166"></td>
          <td id="LC1166" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-en">@<span class="pl-s1">cached_property</span></span> </td>
        </tr>

        <tr class="border-0">
          <td id="L1167" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="1167"></td>
          <td id="LC1167" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-k">def</span> <span class="pl-en">backend</span>(<span class="pl-s1">self</span>): </td>
        </tr>
    </tbody></table>
  </div>
</div>
</li>
<li>Single <code class="notranslate">oid</code> is shared between threads:<br>
This unique identifier is used to define reply-to queue of <code class="notranslate">rpc</code> backend. Again, since the <code class="notranslate">oid</code> is global it is caused that <strong>all</strong> threads are having <strong>single</strong> result queue causing not receiving responses:<br>
<div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/celery/celery/blob/05da357502a109c05b35392391299d75d181ccab/celery/app/base.py#L1152-L1153">celery/celery/app/base.py</a>
    </p>
    <p class="mb-0 color-fg-muted">
        Lines 1152 to 1153
      in
      <a data-pjax="true" class="commit-tease-sha" href="/celery/celery/commit/05da357502a109c05b35392391299d75d181ccab">05da357</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L1152" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="1152"></td>
          <td id="LC1152" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-en">@<span class="pl-s1">cached_property</span></span> </td>
        </tr>

        <tr class="border-0">
          <td id="L1153" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="1153"></td>
          <td id="LC1153" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-k">def</span> <span class="pl-en">oid</span>(<span class="pl-s1">self</span>): </td>
        </tr>
    </tbody></table>
  </div>
</div>
</li>
</ol>
<h1 dir="auto">Possible solution</h1>
<p dir="auto">Store these global variables to thread local storage:<br>
<a href="https://docs.python.org/3/library/threading.html#thread-local-data" rel="nofollow">https://docs.python.org/3/library/threading.html#thread-local-data</a></p>
<h2 dir="auto">Checklist</h2>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have included the output of <code class="notranslate">celery -A proj report</code> in the issue.<br>
(if you are not able to do this, then at least specify the Celery<br>
version affected).</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have verified that the issue exists against the <code class="notranslate">master</code> branch of Celery.</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="software -&gt; celery:4.1.0 (latentcall) kombu:4.1.0 py:3.5.4
            billiard:3.5.0.3 py-amqp:2.2.2
platform -&gt; system:Linux arch:64bit imp:CPython
loader   -&gt; celery.loaders.app.AppLoader
settings -&gt; transport:amqp results:rpc:///

result_backend: 'rpc:///'
broker_url: 'amqp://guest:********@localhost:5672//'"><pre class="notranslate"><code class="notranslate">software -&gt; celery:4.1.0 (latentcall) kombu:4.1.0 py:3.5.4
            billiard:3.5.0.3 py-amqp:2.2.2
platform -&gt; system:Linux arch:64bit imp:CPython
loader   -&gt; celery.loaders.app.AppLoader
settings -&gt; transport:amqp results:rpc:///

result_backend: 'rpc:///'
broker_url: 'amqp://guest:********@localhost:5672//'
</code></pre></div>
<h2 dir="auto">Steps to reproduce</h2>
<p dir="auto">Using code from the user manual, but two threads running concurrently:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from celery import Celery
import time
from threading import Thread

app = Celery('test', broker='amqp://guest@localhost//', backend='rpc://')

@app.task(bind=True)
def hello(self, a, b):
    time.sleep(1)
    self.update_state(state=&quot;PROGRESS&quot;, meta={'progress': 50})
    time.sleep(1)
    self.update_state(state=&quot;PROGRESS&quot;, meta={'progress': 90})
    time.sleep(1)
    return 'hello world: %i' % (a+b)

if __name__ == '__main__':
    def run ():
        handle = hello.delay (1, 2)
        print (handle.get ())
    t1 = Thread (target=run)
    t2 = Thread (target=run)
    t1.start ()
    t2.start ()
    t1.join ()
    t2.join ()"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">celery</span> <span class="pl-k">import</span> <span class="pl-v">Celery</span>
<span class="pl-k">import</span> <span class="pl-s1">time</span>
<span class="pl-k">from</span> <span class="pl-s1">threading</span> <span class="pl-k">import</span> <span class="pl-v">Thread</span>

<span class="pl-s1">app</span> <span class="pl-c1">=</span> <span class="pl-v">Celery</span>(<span class="pl-s">'test'</span>, <span class="pl-s1">broker</span><span class="pl-c1">=</span><span class="pl-s">'amqp://guest@localhost//'</span>, <span class="pl-s1">backend</span><span class="pl-c1">=</span><span class="pl-s">'rpc://'</span>)

<span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-en">task</span>(<span class="pl-s1">bind</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)</span>
<span class="pl-k">def</span> <span class="pl-en">hello</span>(<span class="pl-s1">self</span>, <span class="pl-s1">a</span>, <span class="pl-s1">b</span>):
    <span class="pl-s1">time</span>.<span class="pl-en">sleep</span>(<span class="pl-c1">1</span>)
    <span class="pl-s1">self</span>.<span class="pl-en">update_state</span>(<span class="pl-s1">state</span><span class="pl-c1">=</span><span class="pl-s">"PROGRESS"</span>, <span class="pl-s1">meta</span><span class="pl-c1">=</span>{<span class="pl-s">'progress'</span>: <span class="pl-c1">50</span>})
    <span class="pl-s1">time</span>.<span class="pl-en">sleep</span>(<span class="pl-c1">1</span>)
    <span class="pl-s1">self</span>.<span class="pl-en">update_state</span>(<span class="pl-s1">state</span><span class="pl-c1">=</span><span class="pl-s">"PROGRESS"</span>, <span class="pl-s1">meta</span><span class="pl-c1">=</span>{<span class="pl-s">'progress'</span>: <span class="pl-c1">90</span>})
    <span class="pl-s1">time</span>.<span class="pl-en">sleep</span>(<span class="pl-c1">1</span>)
    <span class="pl-k">return</span> <span class="pl-s">'hello world: %i'</span> <span class="pl-c1">%</span> (<span class="pl-s1">a</span><span class="pl-c1">+</span><span class="pl-s1">b</span>)

<span class="pl-k">if</span> <span class="pl-s1">__name__</span> <span class="pl-c1">==</span> <span class="pl-s">'__main__'</span>:
    <span class="pl-k">def</span> <span class="pl-en">run</span> ():
        <span class="pl-s1">handle</span> <span class="pl-c1">=</span> <span class="pl-s1">hello</span>.<span class="pl-en">delay</span> (<span class="pl-c1">1</span>, <span class="pl-c1">2</span>)
        <span class="pl-en">print</span> (<span class="pl-s1">handle</span>.<span class="pl-en">get</span> ())
    <span class="pl-s1">t1</span> <span class="pl-c1">=</span> <span class="pl-v">Thread</span> (<span class="pl-s1">target</span><span class="pl-c1">=</span><span class="pl-s1">run</span>)
    <span class="pl-s1">t2</span> <span class="pl-c1">=</span> <span class="pl-v">Thread</span> (<span class="pl-s1">target</span><span class="pl-c1">=</span><span class="pl-s1">run</span>)
    <span class="pl-s1">t1</span>.<span class="pl-en">start</span> ()
    <span class="pl-s1">t2</span>.<span class="pl-en">start</span> ()
    <span class="pl-s1">t1</span>.<span class="pl-en">join</span> ()
    <span class="pl-s1">t2</span>.<span class="pl-en">join</span> ()</pre></div>
<h2 dir="auto">Expected behavior</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="hello world: 3
hello world: 3"><pre class="notranslate"><code class="notranslate">hello world: 3
hello world: 3
</code></pre></div>
<h2 dir="auto">Actual behavior</h2>
<p dir="auto">Different exceptions, depending on timing. For instance:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Exception in thread Thread-1:
Traceback (most recent call last):
  File &quot;/…/sandbox/lib/python3.5/site-packages/celery/backends/async.py&quot;, line 154, in add_pending_result
    self._maybe_resolve_from_buffer(result)
  File &quot;/…/sandbox/lib/python3.5/site-packages/celery/backends/async.py&quot;, line 160, in _maybe_resolve_from_buffer
    result._maybe_set_cache(self._pending_messages.take(result.id))
  File &quot;/…/sandbox/lib/python3.5/site-packages/celery/utils/collections.py&quot;, line 871, in take
    raise self.Empty()
queue.Empty

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File &quot;/…/sandbox/lib/python3.5/site-packages/amqp/connection.py&quot;, line 456, in channel
    return self.channels[channel_id]
KeyError: None

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File &quot;/usr/lib64/python3.5/threading.py&quot;, line 914, in _bootstrap_inner
    self.run()
  File &quot;/usr/lib64/python3.5/threading.py&quot;, line 862, in run
    self._target(*self._args, **self._kwargs)
  File &quot;test.py&quot;, line 19, in run
    print (handle.get ())
  File &quot;/…/sandbox/lib/python3.5/site-packages/celery/result.py&quot;, line 193, in get
    self.backend.add_pending_result(self)
  File &quot;/…/sandbox/lib/python3.5/site-packages/celery/backends/async.py&quot;, line 156, in add_pending_result
    self._add_pending_result(result.id, result, weak=weak)
  File &quot;/…/sandbox/lib/python3.5/site-packages/celery/backends/async.py&quot;, line 166, in _add_pending_result
    self.result_consumer.consume_from(task_id)
  File &quot;/…/sandbox/lib/python3.5/site-packages/celery/backends/rpc.py&quot;, line 81, in consume_from
    return self.start(task_id)
  File &quot;/…/sandbox/lib/python3.5/site-packages/celery/backends/rpc.py&quot;, line 56, in start
    self._connection.default_channel, [initial_queue],
  File &quot;/…/sandbox/lib/python3.5/site-packages/kombu/connection.py&quot;, line 821, in default_channel
    self._default_channel = self.channel()
  File &quot;/…/sandbox/lib/python3.5/site-packages/kombu/connection.py&quot;, line 266, in channel
    chan = self.transport.create_channel(self.connection)
  File &quot;/…/sandbox/lib/python3.5/site-packages/kombu/transport/pyamqp.py&quot;, line 100, in create_channel
    return connection.channel()
  File &quot;/…/sandbox/lib/python3.5/site-packages/amqp/connection.py&quot;, line 459, in channel
    channel.open()
  File &quot;/…/sandbox/lib/python3.5/site-packages/amqp/channel.py&quot;, line 432, in open
    spec.Channel.Open, 's', ('',), wait=spec.Channel.OpenOk,
  File &quot;/…/sandbox/lib/python3.5/site-packages/amqp/abstract_channel.py&quot;, line 59, in send_method
    return self.wait(wait, returns_tuple=returns_tuple)
  File &quot;/…/sandbox/lib/python3.5/site-packages/amqp/abstract_channel.py&quot;, line 79, in wait
    self.connection.drain_events(timeout=timeout)
  File &quot;/…/sandbox/lib/python3.5/site-packages/amqp/connection.py&quot;, line 468, in drain_events
    while not self.blocking_read(timeout):
  File &quot;/…/sandbox/lib/python3.5/site-packages/amqp/connection.py&quot;, line 473, in blocking_read
    frame = self.transport.read_frame()
  File &quot;/…/sandbox/lib/python3.5/site-packages/amqp/transport.py&quot;, line 252, in read_frame
    payload = read(size)
  File &quot;/…/sandbox/lib/python3.5/site-packages/amqp/transport.py&quot;, line 417, in _read
    s = recv(n - len(rbuf))
socket.timeout: timed out"><pre class="notranslate"><code class="notranslate">Exception in thread Thread-1:
Traceback (most recent call last):
  File "/…/sandbox/lib/python3.5/site-packages/celery/backends/async.py", line 154, in add_pending_result
    self._maybe_resolve_from_buffer(result)
  File "/…/sandbox/lib/python3.5/site-packages/celery/backends/async.py", line 160, in _maybe_resolve_from_buffer
    result._maybe_set_cache(self._pending_messages.take(result.id))
  File "/…/sandbox/lib/python3.5/site-packages/celery/utils/collections.py", line 871, in take
    raise self.Empty()
queue.Empty

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/…/sandbox/lib/python3.5/site-packages/amqp/connection.py", line 456, in channel
    return self.channels[channel_id]
KeyError: None

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib64/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/usr/lib64/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "test.py", line 19, in run
    print (handle.get ())
  File "/…/sandbox/lib/python3.5/site-packages/celery/result.py", line 193, in get
    self.backend.add_pending_result(self)
  File "/…/sandbox/lib/python3.5/site-packages/celery/backends/async.py", line 156, in add_pending_result
    self._add_pending_result(result.id, result, weak=weak)
  File "/…/sandbox/lib/python3.5/site-packages/celery/backends/async.py", line 166, in _add_pending_result
    self.result_consumer.consume_from(task_id)
  File "/…/sandbox/lib/python3.5/site-packages/celery/backends/rpc.py", line 81, in consume_from
    return self.start(task_id)
  File "/…/sandbox/lib/python3.5/site-packages/celery/backends/rpc.py", line 56, in start
    self._connection.default_channel, [initial_queue],
  File "/…/sandbox/lib/python3.5/site-packages/kombu/connection.py", line 821, in default_channel
    self._default_channel = self.channel()
  File "/…/sandbox/lib/python3.5/site-packages/kombu/connection.py", line 266, in channel
    chan = self.transport.create_channel(self.connection)
  File "/…/sandbox/lib/python3.5/site-packages/kombu/transport/pyamqp.py", line 100, in create_channel
    return connection.channel()
  File "/…/sandbox/lib/python3.5/site-packages/amqp/connection.py", line 459, in channel
    channel.open()
  File "/…/sandbox/lib/python3.5/site-packages/amqp/channel.py", line 432, in open
    spec.Channel.Open, 's', ('',), wait=spec.Channel.OpenOk,
  File "/…/sandbox/lib/python3.5/site-packages/amqp/abstract_channel.py", line 59, in send_method
    return self.wait(wait, returns_tuple=returns_tuple)
  File "/…/sandbox/lib/python3.5/site-packages/amqp/abstract_channel.py", line 79, in wait
    self.connection.drain_events(timeout=timeout)
  File "/…/sandbox/lib/python3.5/site-packages/amqp/connection.py", line 468, in drain_events
    while not self.blocking_read(timeout):
  File "/…/sandbox/lib/python3.5/site-packages/amqp/connection.py", line 473, in blocking_read
    frame = self.transport.read_frame()
  File "/…/sandbox/lib/python3.5/site-packages/amqp/transport.py", line 252, in read_frame
    payload = read(size)
  File "/…/sandbox/lib/python3.5/site-packages/amqp/transport.py", line 417, in _read
    s = recv(n - len(rbuf))
socket.timeout: timed out
</code></pre></div>
<p dir="auto">or</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Exception in thread Thread-1:
Traceback (most recent call last):
  File &quot;/…/sandbox/lib/python3.5/site-packages/celery/backends/async.py&quot;, line 154, in add_pending_result
    self._maybe_resolve_from_buffer(result)
  File &quot;/…/sandbox/lib/python3.5/site-packages/celery/backends/async.py&quot;, line 160, in _maybe_resolve_from_buffer
    result._maybe_set_cache(self._pending_messages.take(result.id))
  File &quot;/…/sandbox/lib/python3.5/site-packages/celery/utils/collections.py&quot;, line 871, in take
    raise self.Empty()
queue.Empty

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File &quot;/usr/lib64/python3.5/threading.py&quot;, line 914, in _bootstrap_inner
    self.run()
  File &quot;/usr/lib64/python3.5/threading.py&quot;, line 862, in run
    self._target(*self._args, **self._kwargs)
  File &quot;test.py&quot;, line 19, in run
    print (handle.get ())
  File &quot;/…/sandbox/lib/python3.5/site-packages/celery/result.py&quot;, line 193, in get
    self.backend.add_pending_result(self)
  File &quot;/…/sandbox/lib/python3.5/site-packages/celery/backends/async.py&quot;, line 156, in add_pending_result
    self._add_pending_result(result.id, result, weak=weak)
  File &quot;/…/sandbox/lib/python3.5/site-packages/celery/backends/async.py&quot;, line 166, in _add_pending_result
    self.result_consumer.consume_from(task_id)
  File &quot;/…/sandbox/lib/python3.5/site-packages/celery/backends/rpc.py&quot;, line 81, in consume_from
    return self.start(task_id)
  File &quot;/…/sandbox/lib/python3.5/site-packages/celery/backends/rpc.py&quot;, line 59, in start
    self._consumer.consume()
  File &quot;/…/sandbox/lib/python3.5/site-packages/kombu/messaging.py&quot;, line 477, in consume
    self._basic_consume(T, no_ack=no_ack, nowait=False)
  File &quot;/…/sandbox/lib/python3.5/site-packages/kombu/messaging.py&quot;, line 598, in _basic_consume
    no_ack=no_ack, nowait=nowait)
  File &quot;/…/sandbox/lib/python3.5/site-packages/kombu/entity.py&quot;, line 737, in consume
    arguments=self.consumer_arguments)
  File &quot;/…/sandbox/lib/python3.5/site-packages/amqp/channel.py&quot;, line 1564, in basic_consume
    wait=None if nowait else spec.Basic.ConsumeOk,
  File &quot;/…/sandbox/lib/python3.5/site-packages/amqp/abstract_channel.py&quot;, line 59, in send_method
    return self.wait(wait, returns_tuple=returns_tuple)
  File &quot;/…/sandbox/lib/python3.5/site-packages/amqp/abstract_channel.py&quot;, line 79, in wait
    self.connection.drain_events(timeout=timeout)
  File &quot;/…/sandbox/lib/python3.5/site-packages/amqp/connection.py&quot;, line 471, in drain_events
    while not self.blocking_read(timeout):
  File &quot;/…/sandbox/lib/python3.5/site-packages/amqp/connection.py&quot;, line 476, in blocking_read
    frame = self.transport.read_frame()
  File &quot;/…/sandbox/lib/python3.5/site-packages/amqp/transport.py&quot;, line 254, in read_frame
    'Received {0:#04x} while expecting 0xce'.format(ch))
amqp.exceptions.UnexpectedFrame: Received 0x3c while expecting 0xce"><pre class="notranslate"><code class="notranslate">Exception in thread Thread-1:
Traceback (most recent call last):
  File "/…/sandbox/lib/python3.5/site-packages/celery/backends/async.py", line 154, in add_pending_result
    self._maybe_resolve_from_buffer(result)
  File "/…/sandbox/lib/python3.5/site-packages/celery/backends/async.py", line 160, in _maybe_resolve_from_buffer
    result._maybe_set_cache(self._pending_messages.take(result.id))
  File "/…/sandbox/lib/python3.5/site-packages/celery/utils/collections.py", line 871, in take
    raise self.Empty()
queue.Empty

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib64/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/usr/lib64/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "test.py", line 19, in run
    print (handle.get ())
  File "/…/sandbox/lib/python3.5/site-packages/celery/result.py", line 193, in get
    self.backend.add_pending_result(self)
  File "/…/sandbox/lib/python3.5/site-packages/celery/backends/async.py", line 156, in add_pending_result
    self._add_pending_result(result.id, result, weak=weak)
  File "/…/sandbox/lib/python3.5/site-packages/celery/backends/async.py", line 166, in _add_pending_result
    self.result_consumer.consume_from(task_id)
  File "/…/sandbox/lib/python3.5/site-packages/celery/backends/rpc.py", line 81, in consume_from
    return self.start(task_id)
  File "/…/sandbox/lib/python3.5/site-packages/celery/backends/rpc.py", line 59, in start
    self._consumer.consume()
  File "/…/sandbox/lib/python3.5/site-packages/kombu/messaging.py", line 477, in consume
    self._basic_consume(T, no_ack=no_ack, nowait=False)
  File "/…/sandbox/lib/python3.5/site-packages/kombu/messaging.py", line 598, in _basic_consume
    no_ack=no_ack, nowait=nowait)
  File "/…/sandbox/lib/python3.5/site-packages/kombu/entity.py", line 737, in consume
    arguments=self.consumer_arguments)
  File "/…/sandbox/lib/python3.5/site-packages/amqp/channel.py", line 1564, in basic_consume
    wait=None if nowait else spec.Basic.ConsumeOk,
  File "/…/sandbox/lib/python3.5/site-packages/amqp/abstract_channel.py", line 59, in send_method
    return self.wait(wait, returns_tuple=returns_tuple)
  File "/…/sandbox/lib/python3.5/site-packages/amqp/abstract_channel.py", line 79, in wait
    self.connection.drain_events(timeout=timeout)
  File "/…/sandbox/lib/python3.5/site-packages/amqp/connection.py", line 471, in drain_events
    while not self.blocking_read(timeout):
  File "/…/sandbox/lib/python3.5/site-packages/amqp/connection.py", line 476, in blocking_read
    frame = self.transport.read_frame()
  File "/…/sandbox/lib/python3.5/site-packages/amqp/transport.py", line 254, in read_frame
    'Received {0:#04x} while expecting 0xce'.format(ch))
amqp.exceptions.UnexpectedFrame: Received 0x3c while expecting 0xce
</code></pre></div>