| 133 | @unittest.skipIf(sys.platform == "win32", "preexec_fn not available on win32") |
| 134 | class ThreadedResolverImportTest(unittest.TestCase): |
| 135 | def test_import(self): |
| 136 | TIMEOUT = 5 |
| 137 | |
| 138 | # Test for a deadlock when importing a module that runs the |
| 139 | # ThreadedResolver at import-time. See resolve_test.py for |
| 140 | # full explanation. |
| 141 | command = [sys.executable, "-c", "import tornado.test.resolve_test_helper"] |
| 142 | |
| 143 | start = time.time() |
| 144 | popen = Popen(command, preexec_fn=lambda: signal.alarm(TIMEOUT)) |
| 145 | while time.time() - start < TIMEOUT: |
| 146 | return_code = popen.poll() |
| 147 | if return_code is not None: |
| 148 | self.assertEqual(0, return_code) |
| 149 | return # Success. |
| 150 | time.sleep(0.05) |
| 151 | |
| 152 | self.fail("import timed out") |
| 153 | |
| 154 | |
| 155 | # We do not test errors with CaresResolver: |