From 18f3e79b13947de0bda7c985916d5a04e28936dc Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Wed, 28 Jan 2015 09:55:52 -0500 Subject: [PATCH] Removed threading fallback imports. Django imports threading in many other places without fallback. --- django/db/backends/base/base.py | 5 +---- django/utils/autoreload.py | 5 +---- django/utils/synch.py | 5 +---- tests/file_storage/tests.py | 6 +----- tests/select_for_update/tests.py | 13 +------------ tests/transactions/tests.py | 5 +---- 6 files changed, 6 insertions(+), 33 deletions(-) diff --git a/django/db/backends/base/base.py b/django/db/backends/base/base.py index fb9260d8ca..cbc4983046 100644 --- a/django/db/backends/base/base.py +++ b/django/db/backends/base/base.py @@ -10,10 +10,7 @@ from django.db.backends import utils from django.db.transaction import TransactionManagementError from django.db.utils import DatabaseError, DatabaseErrorWrapper from django.utils.functional import cached_property -try: - from django.utils.six.moves import _thread as thread -except ImportError: - from django.utils.six.moves import _dummy_thread as thread +from django.utils.six.moves import _thread as thread NO_DB_ALIAS = '__no_db__' diff --git a/django/utils/autoreload.py b/django/utils/autoreload.py index e7df8c8938..0fa6ee2855 100644 --- a/django/utils/autoreload.py +++ b/django/utils/autoreload.py @@ -39,10 +39,7 @@ import traceback from django.apps import apps from django.conf import settings from django.core.signals import request_finished -try: - from django.utils.six.moves import _thread as thread -except ImportError: - from django.utils.six.moves import _dummy_thread as thread +from django.utils.six.moves import _thread as thread # This import does nothing, but it's necessary to avoid some race conditions # in the threading module. See http://code.djangoproject.com/ticket/2330 . diff --git a/django/utils/synch.py b/django/utils/synch.py index 8bb7293fd4..c8ef2f07bd 100644 --- a/django/utils/synch.py +++ b/django/utils/synch.py @@ -7,10 +7,7 @@ Synchronization primitives: """ import contextlib -try: - import threading -except ImportError: - import dummy_threading as threading +import threading class RWLock(object): diff --git a/tests/file_storage/tests.py b/tests/file_storage/tests.py index 4edee3cb80..2718f07cad 100644 --- a/tests/file_storage/tests.py +++ b/tests/file_storage/tests.py @@ -6,16 +6,12 @@ import os import shutil import sys import tempfile +import threading import time import unittest import warnings from datetime import datetime, timedelta -try: - import threading -except ImportError: - import dummy_threading as threading - from django.core.cache import cache from django.core.exceptions import SuspiciousOperation, SuspiciousFileOperation from django.core.files.base import File, ContentFile diff --git a/tests/select_for_update/tests.py b/tests/select_for_update/tests.py index d3f71ab65c..abd7bd2ed4 100644 --- a/tests/select_for_update/tests.py +++ b/tests/select_for_update/tests.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals +import threading import time -import unittest from django.conf import settings from django.db import transaction, connection, router @@ -15,14 +15,6 @@ from multiple_database.routers import TestRouter from .models import Person -# Some tests require threading, which might not be available. So create a -# skip-test decorator for those test functions. -try: - import threading -except ImportError: - threading = None -requires_threading = unittest.skipUnless(threading, 'requires threading') - # We need to set settings.DEBUG to True so we can capture the output SQL # to examine. @@ -92,7 +84,6 @@ class SelectForUpdateTests(TransactionTestCase): list(Person.objects.all().select_for_update(nowait=True)) self.assertTrue(self.has_for_update_sql(connection, nowait=True)) - @requires_threading @skipUnlessDBFeature('has_select_for_update_nowait') def test_nowait_raises_error_on_block(self): """ @@ -173,7 +164,6 @@ class SelectForUpdateTests(TransactionTestCase): # database connection. Close it without waiting for the GC. connection.close() - @requires_threading @skipUnlessDBFeature('has_select_for_update') @skipUnlessDBFeature('supports_transactions') def test_block(self): @@ -223,7 +213,6 @@ class SelectForUpdateTests(TransactionTestCase): p = Person.objects.get(pk=self.person.pk) self.assertEqual('Fred', p.name) - @requires_threading @skipUnlessDBFeature('has_select_for_update') def test_raw_lock_not_available(self): """ diff --git a/tests/transactions/tests.py b/tests/transactions/tests.py index 005df0ba91..bf4735e0d2 100644 --- a/tests/transactions/tests.py +++ b/tests/transactions/tests.py @@ -1,10 +1,7 @@ from __future__ import unicode_literals import sys -try: - import threading -except ImportError: - threading = None +import threading import time from unittest import skipIf, skipUnless