<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/133914>133914</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [LIT] Tests take entire timeout duration after failing when exception is thrown in internal shell
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          ayylol
      </td>
    </tr>
</table>

<pre>
    When using the internal lit shell, if a test throws an exception and a timeout is set the test will take the entire duration of the timeout before finishing. This can happen for example if we try to execute a non-existent file. The tests hang here, at the `pool.join()` call. https://github.com/llvm/llvm-project/blob/19970535f92c0f2dcda01b7fc60f95945166e424/llvm/utils/lit/lit/run.py#L87-L93

This is related to this:
https://stackoverflow.com/questions/15314189/python-multiprocessing-pool-hangs-at-join

## To Reproduce
1. Add a test that will try to execute a non-existent file:
```
; llvm-project/llvm/test/hang.ll
; RUN: non-existent
```
2. Change the test suite's configuration to use the internal shell. (Remove the `not` from this line)
https://github.com/llvm/llvm-project/blob/c1efd8b663b7db3c717fae8a1991dcc4b8304c8f/llvm/test/lit.cfg.py#L21
3. Run the test with a time out set: 
```
llvm-lit llvm/test/hang.ll -a --timeout=10
```
The test should fail immediately, but the execution of lit will not conclude until the full timeout elapses.

If instead we use the external shell, or not set a timeout then the execution of lit will conclude immediately after the test fails.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVUGP4jgT_TXmUiKK7ZCQQw7MjJBGGn2HVn_as-OUiWeMnY3L3c2_XzmEppvd1e5KCASkyq9evfesYrQnj9ix3Re2-7ZRicYwd-pyccFt-jBcut9G9JCi9SegEcF6wtkrB84SxBGdY-IrWAMKCCMBjXN4jaA84JvGiWzwoPyQ_7ZnDInARohIS7Ol4tU6B6R-4fITerIzwpBmtdQGc31yLe7RhBnBWG_jaP2pgOfRRtDKw6imCT2YMAO-qfPkMMN6Ra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