Skip to content

Commit 594ff80

Browse files
committed
fix: in_main_process
1 parent da763d7 commit 594ff80

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

codeforlife/servers/base.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import os
77
import sys
8-
from functools import cached_property
98

109

1110
# pylint: disable-next=too-few-public-methods
@@ -14,8 +13,8 @@ class BaseServer:
1413

1514
main_module: str = "application" # The dot-path of the main module.
1615

17-
@cached_property
18-
def in_main_process(self):
16+
@classmethod
17+
def in_main_process(cls):
1918
"""Whether or not this server is running in the main process."""
2019
file_name = os.path.basename(sys.argv[0])
21-
return os.path.splitext(file_name)[0] == self.main_module
20+
return os.path.splitext(file_name)[0] == cls.main_module

codeforlife/servers/celery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def _debug(self, *args, **kwargs):
6969

7070
print(f"Request: {self.request!r}")
7171

72-
if self.in_main_process:
72+
if self.in_main_process():
7373
self.start_background_workers()
7474
self.start_background_beat()
7575

codeforlife/servers/django.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __init__(self, workers: int = int(os.getenv("WORKERS", "0"))):
5656
super().__init__()
5757

5858
# Auto-run if in main process.
59-
if self.in_main_process:
59+
if self.in_main_process():
6060
self.run()
6161

6262
def load_config(self):
@@ -71,8 +71,8 @@ def load_config(self):
7171
def load(self):
7272
return self.asgi_app
7373

74-
@staticmethod
75-
def setup(settings_module: str = "settings"):
74+
@classmethod
75+
def setup(cls, settings_module: str = "settings"):
7676
"""Set up the Django app.
7777
7878
Args:
@@ -83,4 +83,5 @@ def setup(settings_module: str = "settings"):
8383

8484
setup()
8585

86-
call_command("migrate", interactive=False)
86+
if cls.in_main_process():
87+
call_command("migrate", interactive=False)

0 commit comments

Comments
 (0)