Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.

db.py 562B

12345678910111213141516171819
  1. from asgiref.sync import SyncToAsync
  2. from django.db import close_old_connections
  3. class DatabaseSyncToAsync(SyncToAsync):
  4. """
  5. SyncToAsync version that cleans up old database connections when it exits.
  6. """
  7. def thread_handler(self, loop, *args, **kwargs):
  8. close_old_connections()
  9. try:
  10. return super().thread_handler(loop, *args, **kwargs)
  11. finally:
  12. close_old_connections()
  13. # The class is TitleCased, but we want to encourage use as a callable/decorator
  14. database_sync_to_async = DatabaseSyncToAsync