Skip to content

Commit

Permalink
Restore CUDA_VISIBLE_DEVICES after test
Browse files Browse the repository at this point in the history
Signed-off-by: Enrico Minack <github@enrico.minack.dev>
  • Loading branch information
EnricoMi committed Mar 1, 2022
1 parent 787fcb9 commit 06e9969
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions test/single/test_ray.py
Expand Up @@ -5,7 +5,6 @@
import os
import socket
import sys
import time

import pytest
import ray
Expand Down Expand Up @@ -39,19 +38,27 @@ def ray_start_4_cpus():
@pytest.fixture
def ray_start_6_cpus():
address_info = ray.init(num_cpus=6)
yield address_info
# The code after the yield will run as teardown code.
ray.shutdown()
try:
yield address_info
finally:
# The code after the yield will run as teardown code.
ray.shutdown()


@pytest.fixture
def ray_start_4_cpus_4_gpus():
orig_devices = os.environ.get("CUDA_VISIBLE_DEVICES")
os.environ["CUDA_VISIBLE_DEVICES"] = "0,1,2,3"
address_info = ray.init(num_cpus=4, num_gpus=4)
yield address_info
# The code after the yield will run as teardown code.
ray.shutdown()
del os.environ["CUDA_VISIBLE_DEVICES"]
try:
yield address_info
# The code after the yield will run as teardown code.
ray.shutdown()
finally:
if orig_devices:
os.environ["CUDA_VISIBLE_DEVICES"] = orig_devices
else:
del os.environ["CUDA_VISIBLE_DEVICES"]


@pytest.fixture
Expand Down

0 comments on commit 06e9969

Please sign in to comment.