Make some tests more frienly to MemoryError.
Free memory, unlock hanging threads.
diff --git a/Lib/test/lock_tests.py b/Lib/test/lock_tests.py
index 966f9bd..2ff75c4 100644
--- a/Lib/test/lock_tests.py
+++ b/Lib/test/lock_tests.py
@@ -39,8 +39,12 @@
                 self.finished.append(tid)
                 while not self._can_exit:
                     _wait()
-        for i in range(n):
-            start_new_thread(task, ())
+        try:
+            for i in range(n):
+                start_new_thread(task, ())
+        except:
+            self._can_exit = True
+            raise
 
     def wait_for_started(self):
         while len(self.started) < self.n: