<p dir="auto">Error happens when there's some queues already added before worker started and max task per child is 1</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"> I have included the output of <code class="notranslate">celery -A proj report</code> in the issue.<br>
software -&gt; celery:4.1.0 (latentcall) kombu:4.1.0 py:2.7.12<br>
billiard:3.5.0.3 py-amqp:2.2.2<br>
platform -&gt; system:Linux arch:64bit, ELF imp:CPython<br>
loader   -&gt; celery.loaders.app.AppLoader<br>
settings -&gt; transport:amqp results:disabled</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have verified that the issue exists against the <code class="notranslate">master</code> branch of Celery.</li>
</ul>
<h2 dir="auto">Steps to reproduce</h2>
<ol dir="auto">
<li>create instance of QApplication when main worker started</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="@celeryd_after_setup.connect
from PyQt4.QtGui import QApplication
def init_worker(sender, **k):
    QApplication([])"><pre class="notranslate"><code class="notranslate">@celeryd_after_setup.connect
from PyQt4.QtGui import QApplication
def init_worker(sender, **k):
    QApplication([])
</code></pre></div>
<ol start="2" dir="auto">
<li>create task</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="@app.task
def job():
    print 'hello'"><pre class="notranslate"><code class="notranslate">@app.task
def job():
    print 'hello'
</code></pre></div>
<ol start="3" dir="auto">
<li>
<p dir="auto">add some queues (2 - 3 per thread. so if there's 4 worker child then there's 8 or more queues)</p>
</li>
<li>
<p dir="auto">start worker with max task per child 1</p>
</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="celery worker -A proj --loglevel=INFO --max-tasks-per-child=1"><pre class="notranslate"><code class="notranslate">celery worker -A proj --loglevel=INFO --max-tasks-per-child=1
</code></pre></div>
<h2 dir="auto">Expected behavior</h2>
<ul dir="auto">
<li>run queues successfuly</li>
</ul>
<h2 dir="auto">Actual behavior</h2>
<p dir="auto">Celery Crash after 1 queue per child</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="2017-12-07 10:20:19,594: INFO/MainProcess] Received task: proj.tasks.job[c6413dc2-ad62-4033-a69b-39556276f789]  
[2017-12-07 10:20:19,595: INFO/MainProcess] Received task: proj.tasks.job[f1c10b1c-03ae-4220-9c7f-2cdf4afc61e3]  
[2017-12-07 10:20:19,596: INFO/MainProcess] Received task: proj.tasks.job[d54f4554-4517-470f-8e14-adedcb93a46e]  
[2017-12-07 10:20:19,596: INFO/MainProcess] Received task: proj.tasks.job[6255e5e6-d4c8-4d87-8075-642bca9e6a6d]  
[2017-12-07 10:20:19,700: INFO/ForkPoolWorker-1] Task proj.tasks.job[ca856d5c-f3cc-45d4-9fbc-665753f5d1d2] succeeded in 0.00115608799388s: None
[2017-12-07 10:20:19,701: INFO/ForkPoolWorker-4] Task proj.tasks.job[9ae27611-e8e5-4e08-9815-1e56e2ad1565] succeeded in 0.00130111300678s: None
[2017-12-07 10:20:19,701: INFO/ForkPoolWorker-3] Task proj.tasks.job[f5aa7c6a-4142-4a38-8814-c60424196826] succeeded in 0.00129756200477s: None
[2017-12-07 10:20:19,702: INFO/ForkPoolWorker-2] Task proj.tasks.job[eb13b5c5-8865-4992-8b9e-6672c909fd59] succeeded in 0.00100053900678s: None
[2017-12-07 10:20:19,710: INFO/MainProcess] Received task: proj.tasks.job[01700061-c69c-4f4c-abf2-e6ba200772bd]  
[2017-12-07 10:20:19,711: INFO/MainProcess] Received task: proj.tasks.job[a27d7a7b-2c58-4689-8b98-2c0a4ceaea9f]  
[2017-12-07 10:20:19,713: INFO/MainProcess] Received task: proj.tasks.job[4c4a5685-23d5-4178-89cc-9ce4ad5a3509]  
[2017-12-07 10:20:19,714: INFO/MainProcess] Received task: proj.tasks.job[44a079a3-aacf-48c5-a76b-a061bdced1d6]
[2017-12-07 01:41:03,591: CRITICAL/MainProcess] Unrecoverable error: AttributeError(&quot;'error' object has no attribute 'errno'&quot;,)
Traceback (most recent call last):
  File &quot;/usr/local/lib/python2.7/dist-packages/celery/worker/worker.py&quot;, line 203, in start
    self.blueprint.start(self)
  File &quot;/usr/local/lib/python2.7/dist-packages/celery/bootsteps.py&quot;, line 119, in start
    step.start(parent)
  File &quot;/usr/local/lib/python2.7/dist-packages/celery/bootsteps.py&quot;, line 370, in start
    return self.obj.start()
  File &quot;/usr/local/lib/python2.7/dist-packages/celery/worker/consumer/consumer.py&quot;, line 320, in start
    blueprint.start(self)
  File &quot;/usr/local/lib/python2.7/dist-packages/celery/bootsteps.py&quot;, line 119, in start
    step.start(parent)
  File &quot;/usr/local/lib/python2.7/dist-packages/celery/worker/consumer/consumer.py&quot;, line 596, in start
    c.loop(*c.loop_args())
  File &quot;/usr/local/lib/python2.7/dist-packages/celery/worker/loops.py&quot;, line 88, in asynloop
    next(loop)
  File &quot;/usr/local/lib/python2.7/dist-packages/kombu/async/hub.py&quot;, line 354, in create_loop
    cb(*cbargs)
  File &quot;/usr/local/lib/python2.7/dist-packages/celery/concurrency/asynpool.py&quot;, line 444, in _event_process_exit
    self.maintain_pool()
  File &quot;/usr/local/lib/python2.7/dist-packages/billiard/pool.py&quot;, line 1307, in maintain_pool
    self._maintain_pool()
  File &quot;/usr/local/lib/python2.7/dist-packages/billiard/pool.py&quot;, line 1298, in _maintain_pool
    joined = self._join_exited_workers()
  File &quot;/usr/local/lib/python2.7/dist-packages/billiard/pool.py&quot;, line 1165, in _join_exited_workers
    self.process_flush_queues(worker)
  File &quot;/usr/local/lib/python2.7/dist-packages/celery/concurrency/asynpool.py&quot;, line 1175, in process_flush_queues
    readable, _, _ = _select(fds, None, fds, timeout=0.01)
  File &quot;/usr/local/lib/python2.7/dist-packages/celery/concurrency/asynpool.py&quot;, line 183, in _select
    if exc.errno == errno.EINTR:
AttributeError: 'error' object has no attribute 'errno'"><pre class="notranslate"><code class="notranslate">2017-12-07 10:20:19,594: INFO/MainProcess] Received task: proj.tasks.job[c6413dc2-ad62-4033-a69b-39556276f789]  
[2017-12-07 10:20:19,595: INFO/MainProcess] Received task: proj.tasks.job[f1c10b1c-03ae-4220-9c7f-2cdf4afc61e3]  
[2017-12-07 10:20:19,596: INFO/MainProcess] Received task: proj.tasks.job[d54f4554-4517-470f-8e14-adedcb93a46e]  
[2017-12-07 10:20:19,596: INFO/MainProcess] Received task: proj.tasks.job[6255e5e6-d4c8-4d87-8075-642bca9e6a6d]  
[2017-12-07 10:20:19,700: INFO/ForkPoolWorker-1] Task proj.tasks.job[ca856d5c-f3cc-45d4-9fbc-665753f5d1d2] succeeded in 0.00115608799388s: None
[2017-12-07 10:20:19,701: INFO/ForkPoolWorker-4] Task proj.tasks.job[9ae27611-e8e5-4e08-9815-1e56e2ad1565] succeeded in 0.00130111300678s: None
[2017-12-07 10:20:19,701: INFO/ForkPoolWorker-3] Task proj.tasks.job[f5aa7c6a-4142-4a38-8814-c60424196826] succeeded in 0.00129756200477s: None
[2017-12-07 10:20:19,702: INFO/ForkPoolWorker-2] Task proj.tasks.job[eb13b5c5-8865-4992-8b9e-6672c909fd59] succeeded in 0.00100053900678s: None
[2017-12-07 10:20:19,710: INFO/MainProcess] Received task: proj.tasks.job[01700061-c69c-4f4c-abf2-e6ba200772bd]  
[2017-12-07 10:20:19,711: INFO/MainProcess] Received task: proj.tasks.job[a27d7a7b-2c58-4689-8b98-2c0a4ceaea9f]  
[2017-12-07 10:20:19,713: INFO/MainProcess] Received task: proj.tasks.job[4c4a5685-23d5-4178-89cc-9ce4ad5a3509]  
[2017-12-07 10:20:19,714: INFO/MainProcess] Received task: proj.tasks.job[44a079a3-aacf-48c5-a76b-a061bdced1d6]
[2017-12-07 01:41:03,591: CRITICAL/MainProcess] Unrecoverable error: AttributeError("'error' object has no attribute 'errno'",)
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/celery/worker/worker.py", line 203, in start
    self.blueprint.start(self)
  File "/usr/local/lib/python2.7/dist-packages/celery/bootsteps.py", line 119, in start
    step.start(parent)
  File "/usr/local/lib/python2.7/dist-packages/celery/bootsteps.py", line 370, in start
    return self.obj.start()
  File "/usr/local/lib/python2.7/dist-packages/celery/worker/consumer/consumer.py", line 320, in start
    blueprint.start(self)
  File "/usr/local/lib/python2.7/dist-packages/celery/bootsteps.py", line 119, in start
    step.start(parent)
  File "/usr/local/lib/python2.7/dist-packages/celery/worker/consumer/consumer.py", line 596, in start
    c.loop(*c.loop_args())
  File "/usr/local/lib/python2.7/dist-packages/celery/worker/loops.py", line 88, in asynloop
    next(loop)
  File "/usr/local/lib/python2.7/dist-packages/kombu/async/hub.py", line 354, in create_loop
    cb(*cbargs)
  File "/usr/local/lib/python2.7/dist-packages/celery/concurrency/asynpool.py", line 444, in _event_process_exit
    self.maintain_pool()
  File "/usr/local/lib/python2.7/dist-packages/billiard/pool.py", line 1307, in maintain_pool
    self._maintain_pool()
  File "/usr/local/lib/python2.7/dist-packages/billiard/pool.py", line 1298, in _maintain_pool
    joined = self._join_exited_workers()
  File "/usr/local/lib/python2.7/dist-packages/billiard/pool.py", line 1165, in _join_exited_workers
    self.process_flush_queues(worker)
  File "/usr/local/lib/python2.7/dist-packages/celery/concurrency/asynpool.py", line 1175, in process_flush_queues
    readable, _, _ = _select(fds, None, fds, timeout=0.01)
  File "/usr/local/lib/python2.7/dist-packages/celery/concurrency/asynpool.py", line 183, in _select
    if exc.errno == errno.EINTR:
AttributeError: 'error' object has no attribute 'errno'
</code></pre></div>
<p dir="auto">We are seeing the above mentioned error.<br>
Coming from:<br>
<a href="https://github.com/celery/celery/blob/master/celery/concurrency/asynpool.py#L182">https://github.com/celery/celery/blob/master/celery/concurrency/asynpool.py#L182</a></p>
<p dir="auto">A quick test on this test in the REPL reproduces this error:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Python 2.7.13 (default, Apr  4 2017, 08:46:44)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.
&gt;&gt;&gt; import select
&gt;&gt;&gt; select.error
&lt;class 'select.error'&gt;
&gt;&gt;&gt; moshe = select.error()
&gt;&gt;&gt; moshe.errorno
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
AttributeError: 'error' object has no attribute 'errorno'"><pre class="notranslate"><span class="pl-v">Python</span> <span class="pl-c1">2.7</span><span class="pl-c1">.13</span> (<span class="pl-s1">default</span>, <span class="pl-v">Apr</span>  <span class="pl-c1">4</span> <span class="pl-c1">2017</span>, <span class="pl-c1">08</span>:<span class="pl-c1">46</span>:<span class="pl-c1">44</span>)
[<span class="pl-v">GCC</span> <span class="pl-c1">4.2</span><span class="pl-c1">.1</span> <span class="pl-v">Compatible</span> <span class="pl-v">Apple</span> <span class="pl-v">LLVM</span> <span class="pl-c1">8.0</span><span class="pl-c1">.0</span> (<span class="pl-s1">clang</span><span class="pl-c1">-</span><span class="pl-c1">800.0</span>.<span class="pl-c1">42.1</span>)] <span class="pl-s1">on</span> <span class="pl-s1">darwin</span>
<span class="pl-v">Type</span> <span class="pl-s">"help"</span>, <span class="pl-s">"copyright"</span>, <span class="pl-s">"credits"</span> <span class="pl-c1">or</span> <span class="pl-s">"license"</span> <span class="pl-k">for</span> <span class="pl-s1">more</span> <span class="pl-s1">information</span>.
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-k">import</span> <span class="pl-s1">select</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">select</span>.<span class="pl-s1">error</span>
<span class="pl-c1">&lt;</span><span class="pl-k">class</span> <span class="pl-s">'select.error'</span><span class="pl-c1">&gt;</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">moshe</span> <span class="pl-c1">=</span> <span class="pl-s1">select</span>.<span class="pl-en">error</span>()
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">moshe</span>.<span class="pl-s1">errorno</span>
<span class="pl-v">Traceback</span> (<span class="pl-s1">most</span> <span class="pl-s1">recent</span> <span class="pl-s1">call</span> <span class="pl-s1">last</span>):
  <span class="pl-v">File</span> <span class="pl-s">"&lt;stdin&gt;"</span>, <span class="pl-s1">line</span> <span class="pl-c1">1</span>, <span class="pl-c1">in</span> <span class="pl-c1">&lt;</span><span class="pl-s1">module</span><span class="pl-c1">&gt;</span>
<span class="pl-v">AttributeError</span>: <span class="pl-s">'error'</span> <span class="pl-s1">object</span> <span class="pl-s1">has</span> <span class="pl-s1">no</span> <span class="pl-s1">attribute</span> <span class="pl-s">'errorno'</span></pre></div>
<p dir="auto">With the <em>socket</em> class however, this works just fine:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; import socket
&gt;&gt;&gt; socket.error
&lt;class 'socket.error'&gt;
&gt;&gt;&gt; moshe = socket.error()
&gt;&gt;&gt; moshe.errno"><pre class="notranslate"><span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-k">import</span> <span class="pl-s1">socket</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">socket</span>.<span class="pl-s1">error</span>
<span class="pl-c1">&lt;</span><span class="pl-k">class</span> <span class="pl-s">'socket.error'</span><span class="pl-c1">&gt;</span>
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">moshe</span> <span class="pl-c1">=</span> <span class="pl-s1">socket</span>.<span class="pl-en">error</span>()
<span class="pl-c1">&gt;&gt;</span><span class="pl-c1">&gt;</span> <span class="pl-s1">moshe</span>.<span class="pl-s1">errno</span></pre></div>
<p dir="auto">Given that this code is in place since 2013, maybe I am doing something wrong here?</p>