mirror of
https://github.com/tencentmusic/cube-studio.git
synced 2024-12-15 06:09:57 +08:00
31 lines
831 B
Python
31 lines
831 B
Python
import subprocess
|
|
import fcntl
|
|
import os,sys
|
|
import time
|
|
|
|
import logging
|
|
BASE_LOGGING_CONF = '[%(levelname)s] [%(asctime)s] %(message)s'
|
|
logging.basicConfig(level=logging.INFO,format=BASE_LOGGING_CONF)
|
|
|
|
def nonBlockRead(output):
|
|
fd = output.fileno()
|
|
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
|
|
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
|
|
try:
|
|
return output.readline()
|
|
except:
|
|
return ''
|
|
|
|
class HiddenPrints:
|
|
def __enter__(self):
|
|
self._original_stdout = sys.stdout
|
|
self._original_stderr = sys.stderr
|
|
sys.stdout = open(os.devnull, 'w')
|
|
sys.stderr = open(os.devnull, 'w')
|
|
|
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
sys.stdout.close()
|
|
sys.stderr.close()
|
|
sys.stdout = self._original_stdout
|
|
sys.stderr = self._original_stderr
|