altairbow / django-db-connection-pool

Database connection pool component library for Django
https://pypi.python.org/pypi/django-db-connection-pool/
MIT License
195 stars 24 forks source link

django startup error (environment: python(v3.8) django(v4.0) pymysql(v1.0.2) django-db-connection-pool(v1.0.7)) #26

Closed skotori closed 2 years ago

skotori commented 2 years ago

File "...\lib\site-packages\django\db\utils.py", line 122, in load_backend raise ImproperlyConfigured( django.core.exceptions.ImproperlyConfigured: 'dj_db_conn_pool.backends.mysql' isn't an available database backend or couldn't be imported. Check the above exception. To use one of the built-in backends, use 'django.db.backends.XXX', where XXX is one of: 'mysql', 'oracle', 'postgresql', 'sqlite3'

skotori commented 2 years ago

the django-db-connection-pool is installed by 'pip install django-db-connection-pool'

altairbow commented 2 years ago

Has django-db- connection-pool been installed yet?

skotori commented 2 years ago

Has django-db- connection-pool been installed yet?

yes

skotori commented 2 years ago

Has django-db- connection-pool been installed yet?

TBCXCD.png

skotori commented 2 years ago

Maybe Django 4.0 changed the database backends API.What is the latest version of Django based on

skotori commented 2 years ago

Django started after it was lowered from 4.0 to 3.2.Are there plans to support Django version 4.0

altairbow commented 2 years ago

Django started after it was lowered from 4.0 to 3.2.Are there plans to support Django version 4.0

Caused by Deprecate ugettext(), ugettext_lazy(), ugettext_noop(), ungettext(), and ungettext_lazy(), I will fix it soon

altairbow commented 2 years ago

ImproperlyConfigured has been fixed in django4_support branch, You can test it in your case.

skotori commented 2 years ago

installed the django4_support branch by 'pip install git+https://github.com/altairbow/django-db-connection-pool.git@django4_support', start normally in Django 4.0 environment

skotori commented 2 years ago

There is a problem. I don't know if it's because of my code. Start 100 threads to execute database insert, and the code will be stuck after execution for a period of time.

skotori commented 2 years ago

The length of time the code runs before it gets stuck is proportional to POOL_SIZE.

skotori commented 2 years ago

My configuration is "'POOL_OPTIONS': { 'POOL_SIZE': 10, 'MAX_OVERFLOW': 10, 'RECYCLE': 24 60 60 }". Is it because threads do not share a connection, and then the connection expires too long, resulting in thread blocking.

altairbow commented 2 years ago

Has conn.close been called after your thread done it's work?

skotori commented 2 years ago

Has conn.close been called after your thread done it's work?

No, the connection is not closed.

altairbow commented 2 years ago

You should call conn.close to release the connection

skotori commented 2 years ago

You should call conn.close to release the connection

But I use Django's ORM, MODEL method.

altairbow commented 2 years ago

Django close all database connections automatically after django.core.signals.request_finished received, means Django won't release database connection before your threads finish, don't start too many threads for single user request, it's not a good idea in web development, If it's a background task, you have two choices: 1. Increase MAX_OVERFLOW or POOL_SIZE 2. in your code,call conn.close() to release database connection to pool manually

altairbow commented 2 years ago

fixed by #27

skotori commented 2 years ago

ok, thank you.

imperio59 commented 2 years ago

Can we get a new release with this fix in? 1.0.7 does not contain this fix.

altairbow commented 2 years ago

Can we get a new release with this fix in? 1.0.7 does not contain this fix.

1.1.0 has been released.