Skip to content

Added option to hide terminal window #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions GPUtil/GPUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from subprocess import Popen, PIPE
from subprocess import Popen, PIPE, check_output
from distutils import spawn
import os
import math
Expand All @@ -39,8 +39,8 @@
import sys
import platform


__version__ = '1.4.0'
CREATE_NO_WINDOW = 0x08000000

class GPU:
def __init__(self, ID, uuid, load, memoryTotal, memoryUsed, memoryFree, driver, gpu_name, serial, display_mode, display_active, temp_gpu):
Expand All @@ -65,7 +65,7 @@ def safeFloatCast(strNumber):
number = float('nan')
return number

def getGPUs():
def getGPUs(hide_terminal_pop_up=True):
if platform.system() == "Windows":
# If the platform is Windows and nvidia-smi
# could not be found from the environment path,
Expand All @@ -77,11 +77,22 @@ def getGPUs():
nvidia_smi = "nvidia-smi"

# Get ID, processing and memory utilization for all GPUs
try:
p = Popen([nvidia_smi,"--query-gpu=index,uuid,utilization.gpu,memory.total,memory.used,memory.free,driver_version,name,gpu_serial,display_active,display_mode,temperature.gpu", "--format=csv,noheader,nounits"], stdout=PIPE)
stdout, stderror = p.communicate()
except:
return []
if hide_terminal_pop_up:
try:
stdout = check_output(
[
nvidia_smi,
"--query-gpu=index,uuid,utilization.gpu,memory.total,memory.used,memory.free,driver_version,name,gpu_serial,display_active,display_mode,temperature.gpu",
"--format=csv,noheader,nounits"],
creationflags=CREATE_NO_WINDOW)
except:
return []
else:
try:
p = Popen([nvidia_smi,"--query-gpu=index,uuid,utilization.gpu,memory.total,memory.used,memory.free,driver_version,name,gpu_serial,display_active,display_mode,temperature.gpu", "--format=csv,noheader,nounits"], stdout=PIPE)
stdout, stderror = p.communicate()
except:
return []
output = stdout.decode('UTF-8')
# output = output[2:-1] # Remove b' and ' from string added by python
#print(output)
Expand Down