Skip to content

Instantly share code, notes, and snippets.

Created May 11, 2018 04:22
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Close database connections in thread in Django
from threading import Thread
from django.db import connections
class APIThread(Thread)
def __init__(self, data): = data
def run(self)
# call external api
# process return value
# Django model database access
# close all connections in the thread
for conn in connections:
# create new thread to call api
def make_thread(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment