Fix UnsupportedOperation: fileno in suppress_stdout_stderr (#961)
* bug fixing * llava from readme got this error: UnsupportedOperation: fileno quick fix by checking hasattr * multi modal params fix: add logits = True -> to make llava work * multi modal params fix: add logits = True -> to make llava work --------- Co-authored-by: Andrei <abetlen@gmail.com>
This commit is contained in:
parent
b938cccf05
commit
ac35f68e4d
1 changed files with 16 additions and 10 deletions
|
@ -17,14 +17,18 @@ class suppress_stdout_stderr(object):
|
||||||
if self.disable:
|
if self.disable:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
# Check if sys.stdout and sys.stderr have fileno method
|
||||||
|
if not hasattr(self.sys.stdout, 'fileno') or not hasattr(self.sys.stderr, 'fileno'):
|
||||||
|
return self # Return the instance without making changes
|
||||||
|
|
||||||
self.outnull_file = self.open(self.os.devnull, "w")
|
self.outnull_file = self.open(self.os.devnull, "w")
|
||||||
self.errnull_file = self.open(self.os.devnull, "w")
|
self.errnull_file = self.open(self.os.devnull, "w")
|
||||||
|
|
||||||
self.old_stdout_fileno_undup = self.sys.stdout.fileno()
|
self.old_stdout_fileno_undup = self.sys.stdout.fileno()
|
||||||
self.old_stderr_fileno_undup = self.sys.stderr.fileno()
|
self.old_stderr_fileno_undup = self.sys.stderr.fileno()
|
||||||
|
|
||||||
self.old_stdout_fileno = self.os.dup(self.sys.stdout.fileno())
|
self.old_stdout_fileno = self.os.dup(self.old_stdout_fileno_undup)
|
||||||
self.old_stderr_fileno = self.os.dup(self.sys.stderr.fileno())
|
self.old_stderr_fileno = self.os.dup(self.old_stderr_fileno_undup)
|
||||||
|
|
||||||
self.old_stdout = self.sys.stdout
|
self.old_stdout = self.sys.stdout
|
||||||
self.old_stderr = self.sys.stderr
|
self.old_stderr = self.sys.stderr
|
||||||
|
@ -40,14 +44,16 @@ class suppress_stdout_stderr(object):
|
||||||
if self.disable:
|
if self.disable:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.sys.stdout = self.old_stdout
|
# Check if sys.stdout and sys.stderr have fileno method
|
||||||
self.sys.stderr = self.old_stderr
|
if hasattr(self.sys.stdout, 'fileno') and hasattr(self.sys.stderr, 'fileno'):
|
||||||
|
self.sys.stdout = self.old_stdout
|
||||||
|
self.sys.stderr = self.old_stderr
|
||||||
|
|
||||||
self.os.dup2(self.old_stdout_fileno, self.old_stdout_fileno_undup)
|
self.os.dup2(self.old_stdout_fileno, self.old_stdout_fileno_undup)
|
||||||
self.os.dup2(self.old_stderr_fileno, self.old_stderr_fileno_undup)
|
self.os.dup2(self.old_stderr_fileno, self.old_stderr_fileno_undup)
|
||||||
|
|
||||||
self.os.close(self.old_stdout_fileno)
|
self.os.close(self.old_stdout_fileno)
|
||||||
self.os.close(self.old_stderr_fileno)
|
self.os.close(self.old_stderr_fileno)
|
||||||
|
|
||||||
self.outnull_file.close()
|
self.outnull_file.close()
|
||||||
self.errnull_file.close()
|
self.errnull_file.close()
|
||||||
|
|
Loading…
Reference in a new issue