title: Why do multiple celery workers appear to have the same greenlet ID?
body: <p>The following code was run with</p>
  <pre><code># For flask
  gunicorn --bind 0.0.0.0:5000 project:app --access-logfile -
  </code></pre>
  <pre><code># For celery worker
  celery -A project.celery worker --loglevel=info
  </code></pre>
  <p>Both referencing the same file (below)</p>
  <pre><code>import os
  import time
  import threading
  
  from flask import (
      Flask,
      jsonify,
  )
  from flask_sqlalchemy import SQLAlchemy
  from greenlet import getcurrent
  from celery import Celery
  
  import logging
  logging.basicConfig()
  logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
  
  app = Flask(__name__)
  app.config.from_object(&quot;project.config.Config&quot;)
  db = SQLAlchemy(app)
  
  celery = Celery(__name__)
  celery.conf.broker_url = os.environ.get(&quot;CELERY_BROKER_URL&quot;, &quot;redis://redis:6379&quot;)
  celery.conf.result_backend = os.environ.get(&quot;CELERY_RESULT_BACKEND&quot;, &quot;redis://redis:6379&quot;)
  
  
  @app.route(&quot;/update&quot;, methods=['GET'])
  def update():
  
      for i in range(4):
          celery_worker.delay()
  
      return jsonify(result=&quot;success&quot;)
  
  
  @celery.task(name=&quot;celery_worker&quot;)
  def celery_worker():
      time.sleep(1)
      print(getcurrent())
      time.sleep(1)
      print(getcurrent().__hash__())
      time.sleep(1)
      print(threading.local())
      time.sleep(1)
      print(threading.current_thread())
      time.sleep(1)
      print(os.getpid())
  </code></pre>
  <p>Produces logs showing all the workers, despite being on different processes, are on the same thread AND greenlet?</p>
  <p>Logs:</p>
  <pre><code>celery_worker_1  | [2022-08-15 09:50:16,721: INFO/MainProcess] Task celery_worker[f38b203c-51e8-4242-9b3e-e466a208a395] received
  celery_worker_1  | [2022-08-15 09:50:16,722: INFO/MainProcess] Task celery_worker[60afd98f-1139-4962-9aaf-4049261dae06] received
  web_1            | 172.20.0.1 - - [15/Aug/2022:09:50:16 +0000] &quot;GET /update HTTP/1.1&quot; 200 21 &quot;-&quot; &quot;curl/7.68.0&quot;
  celery_worker_1  | [2022-08-15 09:50:16,724: INFO/MainProcess] Task celery_worker[06feb5ee-4ece-4dfa-9d73-acf396be5161] received
  celery_worker_1  | [2022-08-15 09:50:16,725: INFO/MainProcess] Task celery_worker[545068a2-8b28-454d-a8dc-47809adea845] received
  celery_worker_1  | [2022-08-15 09:50:17,724: WARNING/ForkPoolWorker-1] &lt;greenlet.greenlet object at 0x7f7102ff25c0 (otid=0x7f71038996c0) current active started main&gt;
  celery_worker_1  | [2022-08-15 09:50:17,724: WARNING/ForkPoolWorker-8] &lt;greenlet.greenlet object at 0x7f7102ff25c0 (otid=0x7f71038996c0) current active started main&gt;
  celery_worker_1  | [2022-08-15 09:50:17,727: WARNING/ForkPoolWorker-3] &lt;greenlet.greenlet object at 0x7f7102ff25c0 (otid=0x7f71038996c0) current active started main&gt;
  celery_worker_1  | [2022-08-15 09:50:17,727: WARNING/ForkPoolWorker-2] &lt;greenlet.greenlet object at 0x7f7102ff25c0 (otid=0x7f71038996c0) current active started main&gt;
  celery_worker_1  | [2022-08-15 09:50:18,727: WARNING/ForkPoolWorker-1] 8757709894236
  celery_worker_1  | [2022-08-15 09:50:18,727: WARNING/ForkPoolWorker-8] 8757709894236
  celery_worker_1  | [2022-08-15 09:50:18,729: WARNING/ForkPoolWorker-3] 8757709894236
  celery_worker_1  | [2022-08-15 09:50:18,730: WARNING/ForkPoolWorker-2] 8757709894236
  celery_worker_1  | [2022-08-15 09:50:19,729: WARNING/ForkPoolWorker-1] &lt;_thread._local object at 0x7f7101191c20&gt;
  celery_worker_1  | [2022-08-15 09:50:19,729: WARNING/ForkPoolWorker-8] &lt;_thread._local object at 0x7f7101191c20&gt;
  celery_worker_1  | [2022-08-15 09:50:19,731: WARNING/ForkPoolWorker-3] &lt;_thread._local object at 0x7f7101191c20&gt;
  celery_worker_1  | [2022-08-15 09:50:19,731: WARNING/ForkPoolWorker-2] &lt;_thread._local object at 0x7f7101191c20&gt;
  celery_worker_1  | [2022-08-15 09:50:20,731: WARNING/ForkPoolWorker-1] &lt;_MainThread(MainThread, started 140123376166720)&gt;
  celery_worker_1  | [2022-08-15 09:50:20,731: WARNING/ForkPoolWorker-8] &lt;_MainThread(MainThread, started 140123376166720)&gt;
  celery_worker_1  | [2022-08-15 09:50:20,732: WARNING/ForkPoolWorker-2] &lt;_MainThread(MainThread, started 140123376166720)&gt;
  celery_worker_1  | [2022-08-15 09:50:20,732: WARNING/ForkPoolWorker-3] &lt;_MainThread(MainThread, started 140123376166720)&gt;
  celery_worker_1  | [2022-08-15 09:50:21,733: WARNING/ForkPoolWorker-8] 16
  celery_worker_1  | [2022-08-15 09:50:21,733: WARNING/ForkPoolWorker-1] 9
  celery_worker_1  | [2022-08-15 09:50:21,733: WARNING/ForkPoolWorker-2] 10
  celery_worker_1  | [2022-08-15 09:50:21,734: WARNING/ForkPoolWorker-3] 11
  celery_worker_1  | [2022-08-15 09:50:21,743: INFO/ForkPoolWorker-8] Task celery_worker[f38b203c-51e8-4242-9b3e-e466a208a395] succeeded in 5.019944864034187s: None
  celery_worker_1  | [2022-08-15 09:50:21,743: INFO/ForkPoolWorker-2] Task celery_worker[06feb5ee-4ece-4dfa-9d73-acf396be5161] succeeded in 5.016862046031747s: None
  celery_worker_1  | [2022-08-15 09:50:21,743: INFO/ForkPoolWorker-1] Task celery_worker[60afd98f-1139-4962-9aaf-4049261dae06] succeeded in 5.02064540295396s: None
  celery_worker_1  | [2022-08-15 09:50:21,743: INFO/ForkPoolWorker-3] Task celery_worker[545068a2-8b28-454d-a8dc-47809adea845] succeeded in 5.017592608986888s: None
  </code></pre>
  <p>OS is linux.  The celery worker, and flask, are in separate docker containers build from python:3.9.5-slim-buster.</p>
  <p>This is important because some of the tools in the larger project are scoped by thread, and from their perspective they're all running on the same one.</p>