From: Bob Halley Date: Fri, 18 Mar 2022 12:09:34 +0000 (-0700) Subject: threading is always available from 3.7 on X-Git-Tag: v2.3.0rc1~90 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c9225a8f51900dafef72d0a895e15cd1a2745304;p=thirdparty%2Fdnspython.git threading is always available from 3.7 on --- diff --git a/dns/entropy.py b/dns/entropy.py index 50103562..5e1f5e23 100644 --- a/dns/entropy.py +++ b/dns/entropy.py @@ -20,13 +20,9 @@ from typing import Any, Optional import os import hashlib import random +import threading import time -try: - import threading as _threading -except ImportError: # pragma: no cover - import dummy_threading as _threading # type: ignore - class EntropyPool: @@ -39,7 +35,7 @@ class EntropyPool: self.pool_index = 0 self.digest: Optional[bytearray] = None self.next_byte = 0 - self.lock = _threading.Lock() + self.lock = threading.Lock() self.hash = hashlib.sha1() self.hash_len = 20 self.pool = bytearray(b"\0" * self.hash_len) diff --git a/dns/resolver.py b/dns/resolver.py index 3b76100c..ac34be87 100644 --- a/dns/resolver.py +++ b/dns/resolver.py @@ -23,15 +23,11 @@ from urllib.parse import urlparse import contextlib import socket import sys +import threading import time import random import warnings -try: - import threading as _threading -except ImportError: # pragma: no cover - import dummy_threading as _threading # type: ignore - import dns.exception import dns.edns import dns.flags @@ -330,7 +326,7 @@ class CacheStatistics: class CacheBase: def __init__(self): - self.lock = _threading.Lock() + self.lock = threading.Lock() self.statistics = CacheStatistics() def reset_statistics(self) -> None: diff --git a/dns/versioned.py b/dns/versioned.py index 5cf29e99..02e24122 100644 --- a/dns/versioned.py +++ b/dns/versioned.py @@ -5,11 +5,7 @@ from typing import Callable, Deque, Optional, Set, Union import collections - -try: - import threading as _threading -except ImportError: # pragma: no cover - import dummy_threading as _threading # type: ignore +import threading import dns.exception import dns.immutable @@ -73,14 +69,14 @@ class Zone(dns.zone.Zone): # lgtm[py/missing-equals] """ super().__init__(origin, rdclass, relativize) self._versions: Deque[Version] = collections.deque() - self._version_lock = _threading.Lock() + self._version_lock = threading.Lock() if pruning_policy is None: self._pruning_policy = self._default_pruning_policy else: self._pruning_policy = pruning_policy self._write_txn: Optional[Transaction] = None - self._write_event: Optional[_threading.Event] = None - self._write_waiters: Deque[_threading.Event] = collections.deque() + self._write_event: Optional[threading.Event] = None + self._write_waiters: Deque[threading.Event] = collections.deque() self._readers: Set[Transaction] = set() self._commit_version_unlocked( None, WritableVersion(self, replacement=True), origin @@ -145,7 +141,7 @@ class Zone(dns.zone.Zone): # lgtm[py/missing-equals] # Someone else is writing already, so we will have to # wait, but we want to do the actual wait outside the # lock. - event = _threading.Event() + event = threading.Event() self._write_waiters.append(event) # wait (note we gave up the lock!) # diff --git a/dns/win32util.py b/dns/win32util.py index 7a17b0bb..14fc17e0 100644 --- a/dns/win32util.py +++ b/dns/win32util.py @@ -11,10 +11,7 @@ if sys.platform == "win32": import winreg try: - try: - import threading as _threading - except ImportError: # pragma: no cover - import dummy_threading as _threading # type: ignore + import threading import pythoncom import wmi @@ -38,7 +35,7 @@ if sys.platform == "win32": if _have_wmi: - class _WMIGetter(_threading.Thread): + class _WMIGetter(threading.Thread): def __init__(self): super().__init__() self.info = DnsInfo()