Skip to content

Commit 19d1f4d

Browse files
fix: Use Python script with timeout to run client
This commit introduces a Python script to manage the execution of the `runClient` task with a timeout. This is to address the issue where the client process would not terminate on macOS and Windows in the CI environment. - Added a Python script (`.github/workflows/run_with_timeout.py`) that runs a command with a specified timeout and terminates it if it exceeds the time limit. - Updated the GitHub Workflow to set up Python and use this script to run the `runClient` task on all operating systems. This provides a more robust and platform-independent way to ensure the CI job completes.
1 parent 1fa1a3e commit 19d1f4d

File tree

2 files changed

+53
-10
lines changed

2 files changed

+53
-10
lines changed

.github/workflows/print_gl_capabilities.yml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@ jobs:
1818
- name: Make gradlew executable
1919
if: ${{ runner.os != 'Windows' }}
2020
run: chmod +x ./gradlew
21-
- name: Run on Linux
22-
if: runner.os == 'Linux'
23-
run: xvfb-run ./gradlew :example:runClient | grep "GL_ARB_compute_shader"
24-
25-
- name: Run on macOS
26-
if: runner.os == 'macOS'
27-
run: ./gradlew :example:runClient | grep "GL_ARB_compute_shader"
21+
- name: Set up Python
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: '3.x'
2825

29-
- name: Run on Windows
30-
if: runner.os == 'Windows'
31-
run: ./gradlew.bat :example:runClient | findstr "GL_ARB_compute_shader"
26+
- name: Run client with timeout
27+
run: |
28+
if [[ "${{ runner.os }}" == "Linux" ]]; then
29+
python .github/workflows/run_with_timeout.py "xvfb-run ./gradlew :example:runClient" 90
30+
elif [[ "${{ runner.os }}" == "macOS" ]]; then
31+
python .github/workflows/run_with_timeout.py "./gradlew :example:runClient" 90
32+
else
33+
python .github/workflows/run_with_timeout.py "./gradlew.bat :example:runClient" 90
34+
fi
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import subprocess
2+
import sys
3+
import threading
4+
5+
def run_command(command, timeout_sec):
6+
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, shell=True)
7+
8+
def target():
9+
process.wait()
10+
11+
thread = threading.Thread(target=target)
12+
thread.start()
13+
14+
thread.join(timeout_sec)
15+
if thread.is_alive():
16+
print(f"Command timed out after {timeout_sec} seconds. Terminating process.")
17+
process.terminate()
18+
thread.join()
19+
20+
stdout, stderr = process.communicate()
21+
return stdout, stderr, process.returncode
22+
23+
if __name__ == "__main__":
24+
command_to_run = sys.argv[1]
25+
timeout = int(sys.argv[2])
26+
27+
stdout, stderr, returncode = run_command(command_to_run, timeout)
28+
29+
print("STDOUT:")
30+
print(stdout)
31+
32+
print("STDERR:")
33+
print(stderr)
34+
35+
if "GL_ARB_compute_shader" in stdout:
36+
print("Successfully found GL_ARB_compute_shader info.")
37+
sys.exit(0)
38+
else:
39+
print("Could not find GL_ARB_compute_shader info.")
40+
sys.exit(1)

0 commit comments

Comments
 (0)