本文整理匯總了Python中sys.__stderr__方法的典型用法代碼示例。如果您正苦於以下問題:Python sys.__stderr__方法的具體用法?Python sys.__stderr__怎麽用?Python sys.__stderr__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sys
的用法示例。
在下文中一共展示了sys.__stderr__方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: destroy_crashlogfile
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stderr__ [as 別名]
def destroy_crashlogfile(self):
"""Clean up the crash log file and delete it."""
if self._crash_log_file is None:
return
# We use sys.__stderr__ instead of sys.stderr here so this will still
# work when sys.stderr got replaced, e.g. by "Python Tools for Visual
# Studio".
if sys.__stderr__ is not None:
faulthandler.enable(sys.__stderr__)
else:
faulthandler.disable() # type: ignore[unreachable]
try:
self._crash_log_file.close()
os.remove(self._crash_log_file.name)
except OSError:
log.destroy.exception("Could not remove crash log!")
示例2: handle_error
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stderr__ [as 別名]
def handle_error(self, request, client_address):
"""Override TCPServer method
Error message goes to __stderr__. No error message if exiting
normally or socket raised EOF. Other exceptions not handled in
server code will cause os._exit.
"""
try:
raise
except SystemExit:
raise
except:
erf = sys.__stderr__
print>>erf, '\n' + '-'*40
print>>erf, 'Unhandled server exception!'
print>>erf, 'Thread: %s' % threading.currentThread().getName()
print>>erf, 'Client Address: ', client_address
print>>erf, 'Request: ', repr(request)
traceback.print_exc(file=erf)
print>>erf, '\n*** Unrecoverable, server exiting!'
print>>erf, '-'*40
os._exit(0)
#----------------- end class RPCServer --------------------
示例3: manage_socket
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stderr__ [as 別名]
def manage_socket(address):
for i in range(3):
time.sleep(i)
try:
server = MyRPCServer(address, MyHandler)
break
except socket.error as err:
print>>sys.__stderr__,"IDLE Subprocess: socket error: "\
+ err.args[1] + ", retrying...."
else:
print>>sys.__stderr__, "IDLE Subprocess: Connection to "\
"IDLE GUI failed, exiting."
show_socket_error(err, address)
global exit_now
exit_now = True
return
server.handle_request() # A single request only
示例4: idle_showwarning
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stderr__ [as 別名]
def idle_showwarning(
message, category, filename, lineno, file=None, line=None):
"""Show Idle-format warning (after replacing warnings.showwarning).
The differences are the formatter called, the file=None replacement,
which can be None, the capture of the consequence AttributeError,
and the output of a hard-coded prompt.
"""
if file is None:
file = warning_stream
try:
file.write(idle_formatwarning(
message, category, filename, lineno, line=line))
file.write(">>> ")
except (AttributeError, IOError):
pass # if file (probably __stderr__) is invalid, skip warning.
示例5: vPyDeInit
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stderr__ [as 別名]
def vPyDeInit():
global oTKINTER_ROOT, sSTDOUT_FD
if sSTDOUT_FD:
try:
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
sName = sSTDOUT_FD.name
# sShowInfo('vPyDeInit', "Closing %s" % (sName,))
sSTDOUT_FD.write('INFO : vPyDeInit ' + "Closing outfile %s\n" % (sName,))
# oLOG.shutdown()
sSTDOUT_FD.flush()
sSTDOUT_FD.close()
sSTDOUT_FD = None
except Exception as e:
# You probably have not stdout so no point in logging it!
print "Error closing %s\n%s" % (sSTDOUT_FD, str(e),)
sys.exc_clear()
if oTKINTER_ROOT:
oTKINTER_ROOT.destroy()
oTKINTER_ROOT = None
sys.exc_clear()
示例6: _rmtree
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stderr__ [as 別名]
def _rmtree(path):
def _rmtree_inner(path):
for name in os.listdir(path):
fullname = os.path.join(path, name)
try:
mode = os.lstat(fullname).st_mode
except OSError as exc:
print("support.rmtree(): os.lstat(%r) failed with %s" % (fullname, exc),
file=sys.__stderr__)
mode = 0
if stat.S_ISDIR(mode):
_waitfor(_rmtree_inner, fullname, waitall=True)
os.rmdir(fullname)
else:
os.unlink(fullname)
_waitfor(_rmtree_inner, path, waitall=True)
_waitfor(os.rmdir, path)
示例7: test_is_enabled
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stderr__ [as 別名]
def test_is_enabled(self):
orig_stderr = sys.stderr
try:
# regrtest may replace sys.stderr by io.StringIO object, but
# faulthandler.enable() requires that sys.stderr has a fileno()
# method
sys.stderr = sys.__stderr__
was_enabled = faulthandler.is_enabled()
try:
faulthandler.enable()
self.assertTrue(faulthandler.is_enabled())
faulthandler.disable()
self.assertFalse(faulthandler.is_enabled())
finally:
if was_enabled:
faulthandler.enable()
else:
faulthandler.disable()
finally:
sys.stderr = orig_stderr
示例8: serve_forever
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stderr__ [as 別名]
def serve_forever(self):
'''
Run the server forever
'''
self.stop_event = threading.Event()
process.current_process()._manager_server = self
try:
accepter = threading.Thread(target=self.accepter)
accepter.daemon = True
accepter.start()
try:
while not self.stop_event.is_set():
self.stop_event.wait(1)
except (KeyboardInterrupt, SystemExit):
pass
finally:
if sys.stdout != sys.__stdout__:
util.debug('resetting stdout, stderr')
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
sys.exit(0)
示例9: handle_error
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stderr__ [as 別名]
def handle_error(self, request, client_address):
"""Override TCPServer method
Error message goes to __stderr__. No error message if exiting
normally or socket raised EOF. Other exceptions not handled in
server code will cause os._exit.
"""
try:
raise
except SystemExit:
raise
except:
erf = sys.__stderr__
print('\n' + '-'*40, file=erf)
print('Unhandled server exception!', file=erf)
print('Thread: %s' % threading.current_thread().name, file=erf)
print('Client Address: ', client_address, file=erf)
print('Request: ', repr(request), file=erf)
traceback.print_exc(file=erf)
print('\n*** Unrecoverable, server exiting!', file=erf)
print('-'*40, file=erf)
os._exit(0)
#----------------- end class RPCServer --------------------
示例10: manage_socket
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stderr__ [as 別名]
def manage_socket(address):
for i in range(3):
time.sleep(i)
try:
server = MyRPCServer(address, MyHandler)
break
except OSError as err:
print("IDLE Subprocess: OSError: " + err.args[1] +
", retrying....", file=sys.__stderr__)
socket_error = err
else:
print("IDLE Subprocess: Connection to "
"IDLE GUI failed, exiting.", file=sys.__stderr__)
show_socket_error(socket_error, address)
global exit_now
exit_now = True
return
server.handle_request() # A single request only
示例11: execute_code
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stderr__ [as 別名]
def execute_code(cls, code):
""" Executes supplied code as pure python and returns a list of stdout, stderr
Args:
code (string): Python code to execute
Results:
(list): stdout, stderr of executed python code
Raises:
ExecutionError when supplied python is incorrect
Examples:
>>> execute_code('print "foobar"')
'foobar'
"""
output = StringIO.StringIO()
err = StringIO.StringIO()
sys.stdout = output
sys.stderr = err
try:
# pylint: disable=exec-used
exec(code)
# If the code is invalid, just skip the block - any actual code errors
# will be raised properly
except TypeError:
pass
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
results = list()
results.append(output.getvalue())
results.append(err.getvalue())
results = ''.join(results)
return results
示例12: Start
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stderr__ [as 別名]
def Start(self,func=None):
if self.out:
sys.stdout = self
self.origOut = sys.__stdout__
else:
sys.stderr= self
self.origOut = sys.__stderr__
if func:
self.func = func
else:
self.func = self.TestHook
#Stop will stop routing of print statements thru this class
示例13: Stop
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stderr__ [as 別名]
def Stop(self):
self.origOut.flush()
if self.out:
sys.stdout = sys.__stdout__
else:
sys.stderr = sys.__stderr__
self.func = None
#override write of stdout
示例14: init_faulthandler
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stderr__ [as 別名]
def init_faulthandler(fileobj=sys.__stderr__):
"""Enable faulthandler module if available.
This print a nice traceback on segfaults.
We use sys.__stderr__ instead of sys.stderr here so this will still work
when sys.stderr got replaced, e.g. by "Python Tools for Visual Studio".
Args:
fobj: An opened file object to write the traceback to.
"""
if fileobj is None:
# When run with pythonw.exe, sys.__stderr__ can be None:
# https://docs.python.org/3/library/sys.html#sys.__stderr__
# If we'd enable faulthandler in that case, we just get a weird
# exception, so we don't enable faulthandler if we have no stdout.
#
# Later when we have our data dir available we re-enable faulthandler
# to write to a file so we can display a crash to the user at the next
# start.
return
faulthandler.enable(fileobj)
if (hasattr(faulthandler, 'register') and hasattr(signal, 'SIGUSR1') and
sys.stderr is not None):
# If available, we also want a traceback on SIGUSR1.
# pylint: disable=no-member,useless-suppression
faulthandler.register(signal.SIGUSR1)
# pylint: enable=no-member,useless-suppression
示例15: log
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import __stderr__ [as 別名]
def log(self, message, *args):
"""Logs an import-related message to stderr, with indentation based on
current call-stack depth.
Args:
message: Logging format string.
args: Positional format parameters for the logging message.
"""
if HardenedModulesHook.ENABLE_LOGGING:
indent = self._indent_level * ' '
print >>sys.__stderr__, indent + (message % args)