Issue2564: Prevent a hang in "import test.autotest", which runs the entire test
suite as a side-effect of importing the module.

- in test_capi, a thread tried to import other modules
- re.compile() imported sre_parse again on every call.
diff --git a/Lib/test/test_capi.py b/Lib/test/test_capi.py
index cdd84bb..eea41c1 100644
--- a/Lib/test/test_capi.py
+++ b/Lib/test/test_capi.py
@@ -19,9 +19,6 @@
 
     # some extra thread-state tests driven via _testcapi
     def TestThreadState():
-        import thread
-        import time
-
         if test_support.verbose:
             print "auto-thread-state"
 
@@ -45,6 +42,8 @@
         have_thread_state = False
 
     if have_thread_state:
+        import thread
+        import time
         TestThreadState()
         import threading
         t=threading.Thread(target=TestThreadState)