Fix test hang issue (#1406)

* Add try except to resource.setrlimit

* Set time limit only in main thread

* Check only test model

* Pytest debug

* Test separately

* Move test_model.py to automl folder
This commit is contained in:
Li Jiang
2025-02-13 19:50:35 +08:00
committed by GitHub
parent 6d53929803
commit d8b7d25b80
3 changed files with 12 additions and 6 deletions

View File

@@ -85,7 +85,7 @@ jobs:
- name: Test with pytest
if: matrix.python-version != '3.10'
run: |
pytest test
pytest test/
- name: Coverage
if: matrix.python-version == '3.10'
run: |

View File

@@ -9,6 +9,7 @@ import os
import shutil
import signal
import sys
import threading
import time
import warnings
from contextlib import contextmanager
@@ -89,21 +90,25 @@ def limit_resource(memory_limit, time_limit):
except ValueError:
# According to https://bugs.python.org/issue40518, it's a mac-specific error.
pass
main_thread = False
if time_limit is not None:
alarm_set = False
if time_limit is not None and threading.current_thread() is threading.main_thread():
try:
signal.signal(signal.SIGALRM, TimeoutHandler)
signal.alarm(int(time_limit) or 1)
main_thread = True
alarm_set = True
except ValueError:
pass
try:
yield
finally:
if main_thread:
if alarm_set:
signal.alarm(0)
if memory_limit > 0:
resource.setrlimit(resource.RLIMIT_AS, (soft, hard))
try:
resource.setrlimit(resource.RLIMIT_AS, (soft, hard))
except ValueError:
pass
class BaseEstimator:

View File

@@ -143,4 +143,5 @@ def test_prep():
if __name__ == "__main__":
test_lrl2()
test_prep()