From: Bob Halley Date: Tue, 28 Aug 2018 16:06:48 +0000 (-0700) Subject: lock importing to avoid races with multiple threads X-Git-Tag: v1.16.0~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e2a2a5967c98648936e9e45b16271d933c1b127;p=thirdparty%2Fdnspython.git lock importing to avoid races with multiple threads --- diff --git a/dns/rdata.py b/dns/rdata.py index 6f8a3983..5123a241 100644 --- a/dns/rdata.py +++ b/dns/rdata.py @@ -27,6 +27,11 @@ import dns.tokenizer import dns.wiredata from ._compat import xrange, string_types, text_type +try: + import threading as _threading +except ImportError: + import dummy_threading as _threading + _hex_chunksize = 32 @@ -300,16 +305,17 @@ class GenericRdata(Rdata): _rdata_modules = {} _module_prefix = 'dns.rdtypes' - +_import_lock = _threading.Lock() def get_rdata_class(rdclass, rdtype): def import_module(name): - mod = __import__(name) - components = name.split('.') - for comp in components[1:]: - mod = getattr(mod, comp) - return mod + with _import_lock: + mod = __import__(name) + components = name.split('.') + for comp in components[1:]: + mod = getattr(mod, comp) + return mod mod = _rdata_modules.get((rdclass, rdtype)) rdclass_text = dns.rdataclass.to_text(rdclass)