My Django project all is ok when I use python mange.py runserver, but when I use uwsgi --ini uwsgi.ini if I sent a post request there will be error。
the uwsgi.log as follows
*** Starting uWSGI 2.0.21 (64bit) on [Fri Dec 16 08:18:06 2022] ***
compiled with version: 8.3.0 on 15 December 2022 01:20:38
os: Linux-3.10.0-1160.62.1.el7.x86_64 #1 SMP Tue Apr 5 16:57:59 UTC 2022
nodename: c7b8f6774bce
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /root/test_env/garbage_text_classification/API_simple
writing pidfile to uwsgi.pid
detected binary path: /usr/local/bin/uwsgi
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
chdir() to /root/test_env/garbage_text_classification/API_simple
your processes number limit is 1048576
your memory page size is 4096 bytes
detected max file descriptor number: 1048576
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on 0.0.0.0:8000 fd 4
uwsgi socket 0 bound to TCP address 127.0.0.1:45155 (port auto-assigned) fd 3
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
Python version: 3.7.7 (default, Jun 9 2020, 17:58:51) [GCC 8.3.0]
Python main interpreter initialized at 0x55a514e68760
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 312864 bytes (305 KB) for 8 cores
*** Operational MODE: preforking+threaded ***
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x55a514e68760 pid: 8 (default app)
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 8)
spawned uWSGI worker 1 (pid: 9, cores: 4)
spawned uWSGI worker 2 (pid: 10, cores: 4)
spawned uWSGI http 1 (pid: 17
The errot in log is follows:
Internal Server Error: /model_judge/predict_bert
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/usr/local/lib/python3.7/site-packages/django/utils/deprecation.py", line 116, in __call__
response = self.process_request(request)
File "/usr/local/lib/python3.7/site-packages/django/middleware/common.py", line 53, in process_request
if self.should_redirect_with_slash(request):
File "/usr/local/lib/python3.7/site-packages/django/middleware/common.py", line 70, in should_redirect_with_slash
if not is_valid_path(request.path_info, urlconf):
File "/usr/local/lib/python3.7/site-packages/django/urls/base.py", line 153, in is_valid_path
return resolve(path, urlconf)
File "/usr/local/lib/python3.7/site-packages/django/urls/base.py", line 24, in resolve
return get_resolver(urlconf).resolve(path)
File "/usr/local/lib/python3.7/site-packages/django/urls/resolvers.py", line 556, in resolve
for pattern in self.url_patterns:
File "/usr/local/lib/python3.7/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python3.7/site-packages/django/urls/resolvers.py", line 598, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python3.7/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python3.7/site-packages/django/urls/resolvers.py", line 591, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "./Ai_Web/urls.py", line 8, in <module>
url(r'model_judge/',include('model_judge.urls'))
File "/usr/local/lib/python3.7/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "./model_judge/urls.py", line 3, in <module>
from model_judge import views
File "./model_judge/views.py", line 16, in <module>
my_bert = BertClassifier()
File "./model_judge/bert_finetuned.py", line 38, in __init__
self.bertmodel = torch.load(path_to_model,map_location='cpu')
File "/usr/local/lib/python3.7/site-packages/torch/serialization.py", line 607, in load
return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
File "/usr/local/lib/python3.7/site-packages/torch/serialization.py", line 882, in _load
result = unpickler.load()
File "/usr/local/lib/python3.7/site-packages/torch/serialization.py", line 875, in find_class
return super().find_class(mod_name, name)
AttributeError: Can't get attribute 'BertClassificationModel' on <module '__main__' (built-in)>
I try import the 'BertClassificationModel' to the url.py,views.py,init.py,t's also error.
My Django project all is ok when I use
python mange.py runserver
, but when I useuwsgi --ini uwsgi.ini
if I sent a post request there will be error。 the uwsgi.log as followsThe errot in log is follows:
I try import the 'BertClassificationModel' to the url.py,views.py,init.py,t's also error.