#32424: in-memory test database does not work with multiprocessing.apply_async
-------------------------------------+-------------------------------------
Reporter: Tata | Owner: nobody
Krushna Chaitanya |
Type: | Status: new
Uncategorized |
Component: Database | Version: 3.0
layer (models, ORM) | Keywords: sqlite3, threading,
Severity: Normal | tests
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Hi,
I am using Django 3.0 (On Ubuntu 18.04 installed using pip3). The below
example works only with threading but not with
multiprocessing.apply_async. Here is my sample, Looking at the Django code
I have made sure that all requirements are met, I am using py3.6 and the
sqlite3 version is also met.
{{{
$ python3 -c "from sqlite3 import dbapi2 as Database; print
(Database.__name__, Database.sqlite_version_info)"
sqlite3.dbapi2 (3, 22, 0)
}}}
{{{
import os
os.environ["DJANGO_SETTINGS_MODULE"] = "settings"
import datetime, threading
from multiprocessing import Pool
# django stuff
import django
django.setup()
from polls.models import *
from django.core.mail import mail_admins
from django.test.utils import *
from django.db import connection
def create_object():
print("Creating Poll")
p = Question()
p.question_text = "What's up doc ?"
p.pub_date = datetime.date.today()
p.save()
print("Poll object saved. Id: %d" % p.id)
MODULE = 1
if __name__ == "__main__":
setup_test_environment()
old_db_name = "db.sqlite3"
new_db_name = connection.creation.create_test_db(verbosity=1)
print("New DATABASE:", new_db_name)
if MODULE == 0:
t = threading.Thread(target=create_object)
t.start()
t.join()
elif MODULE == 1:
with Pool(2) as p:
p.apply_async(create_object)
else:
create_object()
obj = Question.objects.get()
print(obj.question_text)
teardown_test_environment()
connection.creation.destroy_test_db(old_db_name)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32424>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/052.26ab55214da02a8899620ff630cb2b39%40djangoproject.com.