django-lambda-tasks 0.6.2__py3-none-any.whl → 0.6.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {django_lambda_tasks-0.6.2.dist-info → django_lambda_tasks-0.6.4.dist-info}/METADATA +1 -1
- {django_lambda_tasks-0.6.2.dist-info → django_lambda_tasks-0.6.4.dist-info}/RECORD +4 -4
- lambda_tasks/local_executor.py +20 -1
- {django_lambda_tasks-0.6.2.dist-info → django_lambda_tasks-0.6.4.dist-info}/WHEEL +0 -0
|
@@ -4,7 +4,7 @@ lambda_tasks/apps.py,sha256=Kcr5BDD67J0XkGdbDdKZp6kDQTGUSU0I8xWcCiKILhs,847
|
|
|
4
4
|
lambda_tasks/decorators.py,sha256=e1aaVzTtX2Z5cd2bckY-sKu6B4k4q2J2_A0pxBLYW-s,12830
|
|
5
5
|
lambda_tasks/environment_loader.py,sha256=fflFd2gs7bChuGsP4vYiX0LFJXKRQbrScONqHB7gQt0,4406
|
|
6
6
|
lambda_tasks/handler.py,sha256=c4tOdf31ZYiuSDZW0w96QVN1ZUCzSNp6ZG2oJSTHGl8,5343
|
|
7
|
-
lambda_tasks/local_executor.py,sha256=
|
|
7
|
+
lambda_tasks/local_executor.py,sha256=Vymkk_FgTv9uBTcVkCR2gM6126lPponCJqqZ3TfeCoQ,6527
|
|
8
8
|
lambda_tasks/logging.py,sha256=oIiEU9EoZKF-V-s0mQFlxTEUDKg4hqUrQUcPIYRzeqM,1022
|
|
9
9
|
lambda_tasks/models.py,sha256=xIN951GLekwy1FIzZRgdNTooWStSoBKxqDuLQTVNoTc,10720
|
|
10
10
|
lambda_tasks/secret_loader.py,sha256=matQqoONHVJuvN-ja_JdxULlUAaLUtSTCXUE3FZ9ZhE,6845
|
|
@@ -14,6 +14,6 @@ lambda_tasks/timeouts.py,sha256=vO-0-gmcRPhMbWRmshd2TM5dy_RCdI6oW_WpR50ohNI,2593
|
|
|
14
14
|
lambda_tasks/migrations/0001_initial.py,sha256=73evCSkciOn3e9h8dPp88m4Y_nhHzYC9cz3Fv0WcuUc,2356
|
|
15
15
|
lambda_tasks/migrations/0002_alter_taskrecord_status.py,sha256=9x1bBmcH2zOYgVMpE8FOPkVp74vnVEQNNpP2XeSBs1E,2026
|
|
16
16
|
lambda_tasks/migrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
17
|
-
django_lambda_tasks-0.6.
|
|
18
|
-
django_lambda_tasks-0.6.
|
|
19
|
-
django_lambda_tasks-0.6.
|
|
17
|
+
django_lambda_tasks-0.6.4.dist-info/METADATA,sha256=CjdGAN5LJTBunpoufon4yXOZGMqCGTSXOg9OvL-JdFA,31456
|
|
18
|
+
django_lambda_tasks-0.6.4.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
19
|
+
django_lambda_tasks-0.6.4.dist-info/RECORD,,
|
lambda_tasks/local_executor.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import atexit
|
|
4
4
|
import logging
|
|
5
|
+
import multiprocessing
|
|
5
6
|
import signal
|
|
6
7
|
import threading
|
|
7
8
|
import uuid
|
|
@@ -23,14 +24,22 @@ def _pool_initializer() -> None:
|
|
|
23
24
|
atexit as a fallback). This prevents workers from being killed
|
|
24
25
|
mid-operation and leaking semaphores.
|
|
25
26
|
|
|
27
|
+
Closes all database connections before setting up Django. With the
|
|
28
|
+
forkserver context, workers don't inherit the parent's connections,
|
|
29
|
+
but AppConfig.ready() hooks may open connections during django.setup()
|
|
30
|
+
that should be closed before task execution begins.
|
|
31
|
+
|
|
26
32
|
Then sets up Django for task execution.
|
|
27
33
|
"""
|
|
28
34
|
signal.signal(signal.SIGINT, signal.SIG_IGN)
|
|
29
35
|
|
|
30
36
|
import django
|
|
37
|
+
from django.db import connections
|
|
31
38
|
|
|
32
39
|
django.setup()
|
|
33
40
|
|
|
41
|
+
connections.close_all()
|
|
42
|
+
|
|
34
43
|
|
|
35
44
|
def _shutdown_pool() -> None:
|
|
36
45
|
"""Shut down the pool, releasing its POSIX semaphores promptly.
|
|
@@ -111,12 +120,22 @@ def _install_shutdown_handlers() -> None:
|
|
|
111
120
|
|
|
112
121
|
|
|
113
122
|
def get_pool() -> ProcessPoolExecutor:
|
|
114
|
-
"""Return the shared ProcessPoolExecutor, creating it on first call.
|
|
123
|
+
"""Return the shared ProcessPoolExecutor, creating it on first call.
|
|
124
|
+
|
|
125
|
+
Uses the "forkserver" multiprocessing context so that worker processes
|
|
126
|
+
are forked from a clean server process rather than from the Django parent.
|
|
127
|
+
This prevents workers from inheriting the parent's open database
|
|
128
|
+
connections (and other file descriptors), which would otherwise cause
|
|
129
|
+
"server closed the connection unexpectedly" errors in containerized
|
|
130
|
+
environments where close() in the child tears down the shared socket.
|
|
131
|
+
"""
|
|
115
132
|
global _pool
|
|
116
133
|
if _pool is None:
|
|
117
134
|
conf = LambdaTasksSettings()
|
|
135
|
+
mp_context = multiprocessing.get_context("forkserver")
|
|
118
136
|
_pool = ProcessPoolExecutor(
|
|
119
137
|
max_workers=conf.LOCAL_WORKERS,
|
|
138
|
+
mp_context=mp_context,
|
|
120
139
|
initializer=_pool_initializer,
|
|
121
140
|
)
|
|
122
141
|
atexit.register(_shutdown_pool)
|
|
File without changes
|