The cgitb module had imports in its functions. This can cause deadlock with the
import lock if called from within a thread that was triggered by an import.

Partially fixes issue #1665206.
diff --git a/Misc/NEWS b/Misc/NEWS
index 1d210a1..3d2b492 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -200,6 +200,10 @@
 Library
 -------
 
+- Issue #1665206 (partially): Move imports in cgitb to the top of the module
+  instead of performing them in functions. Helps prevent import deadlocking in
+  threads.
+
 - Actually make the SimpleXMLRPCServer CGI handler work.
 
 - Issue #2522: locale.format now checks its first argument to ensure it has