Программы на Python
-
Anonymous
Почему Gunicorn использует ту же тему
Сообщение
Anonymous »
простое имя Python myapp.py:
Код: Выделить всё
import threading
import os
def app(environ, start_response):
tid = threading.get_ident()
pid = os.getpid()
ppid = os.getppid()
# #####
print('tid ================ ', tid) # why same tid?
# #####
print('pid', pid) #
print('ppid', ppid) #
data = b"Hello, World!\n"
start_response("200 OK", [
("Content-Type", "text/plain"),
("Content-Length", str(len(data)))
])
return iter([data])
И я начинаю с пушки:
gunicorn -w 4 myapp:app
Код: Выделить всё
[2022-03-28 21:59:57 +0800] [55107] [INFO] Starting gunicorn 20.1.0
[2022-03-28 21:59:57 +0800] [55107] [INFO] Listening at: http://127.0.0.1:8000 (55107)
[2022-03-28 21:59:57 +0800] [55107] [INFO] Using worker: sync
[2022-03-28 21:59:57 +0800] [55110] [INFO] Booting worker with pid: 55110
[2022-03-28 21:59:57 +0800] [55111] [INFO] Booting worker with pid: 55111
[2022-03-28 21:59:57 +0800] [55112] [INFO] Booting worker with pid: 55112
[2022-03-28 21:59:57 +0800] [55113] [INFO] Booting worker with pid: 55113
затем закручиваю
http://127.0.0.1:8000/ (или использую браузер). журналы ниже:
Код: Выделить всё
tid ================ 4455738816
pid 55112
ppid 55107
tid ================ 4455738816
pid 55111
ppid 55107
tid ================ 4455738816
pid 55113
ppid 55107
вопрос:
почему tid одинаковый, а pid другой.
ps: код взят из
https://gunicorn.org/ домашняя страница.
Подробнее здесь:
https://stackoverflow.com/questions/716 ... ame-thread
1731626386
Anonymous
простое имя Python myapp.py:
[code]
import threading
import os
def app(environ, start_response):
tid = threading.get_ident()
pid = os.getpid()
ppid = os.getppid()
# #####
print('tid ================ ', tid) # why same tid?
# #####
print('pid', pid) #
print('ppid', ppid) #
data = b"Hello, World!\n"
start_response("200 OK", [
("Content-Type", "text/plain"),
("Content-Length", str(len(data)))
])
return iter([data])
[/code]
И я начинаю с пушки:
gunicorn -w 4 myapp:app
[code][2022-03-28 21:59:57 +0800] [55107] [INFO] Starting gunicorn 20.1.0
[2022-03-28 21:59:57 +0800] [55107] [INFO] Listening at: http://127.0.0.1:8000 (55107)
[2022-03-28 21:59:57 +0800] [55107] [INFO] Using worker: sync
[2022-03-28 21:59:57 +0800] [55110] [INFO] Booting worker with pid: 55110
[2022-03-28 21:59:57 +0800] [55111] [INFO] Booting worker with pid: 55111
[2022-03-28 21:59:57 +0800] [55112] [INFO] Booting worker with pid: 55112
[2022-03-28 21:59:57 +0800] [55113] [INFO] Booting worker with pid: 55113
[/code]
затем закручиваю http://127.0.0.1:8000/ (или использую браузер). журналы ниже:
[code]tid ================ 4455738816
pid 55112
ppid 55107
tid ================ 4455738816
pid 55111
ppid 55107
tid ================ 4455738816
pid 55113
ppid 55107
[/code]
вопрос: [b]почему tid одинаковый, а pid другой[/b].
ps: код взят из https://gunicorn.org/ домашняя страница.
Подробнее здесь: [url]https://stackoverflow.com/questions/71648826/why-gunicorn-use-same-thread[/url]