Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to setup Python environment attributes for a Django project?

For example the Python decimal.Decimal() class has a context. You can view the current context with getcontext() and set new values for precision, rounding, or enable traps.

If you wanted to set a new value for the context so this is visible throughout a Django project, where would be best to do so?

e.g. Throughout the project the FloatOperation signal should be trapped.

from decimal import FloatOperation, getcontext

context = getcontext()
context.traps[FloatOperation] = True

Also using getcontext() return the current context for the active thread. Aside from explicitly creating new threads in a project, are there any additional consideration to make with Django creating additional threads.

like image 263
James Beith Avatar asked Oct 30 '22 15:10

James Beith


1 Answers

I'd suggest an application core, or common, that includes your setup as part of AppConfig.ready().

https://docs.djangoproject.com/en/1.7/ref/applications/#django.apps.AppConfig.ready

like image 96
Tom Christie Avatar answered Nov 08 '22 08:11

Tom Christie