def glut_int_handler(signum, frame):
# Catch sigint and print the defautl message
signal.signal(signal.SIGINT, signal.default_int_handler)
print '\nKeyboardInterrupt'
# Need to reprint the prompt at this stage
#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------
python类default_int_handler()的实例源码
def tearDown(self):
if log.defaultObserver is not None:
log.defaultObserver.start()
TestCase.tearDown(self)
# Trial should restore the handler itself, but doesn't.
# See bug #3888 in Twisted tracker.
signal.signal(signal.SIGINT, signal.default_int_handler)
def remove_signal_handler(self, sig):
"""Remove a handler for a signal. UNIX only.
Return True if a signal handler was removed, False if not.
"""
self._check_signal(sig)
try:
del self._signal_handlers[sig]
except KeyError:
return False
if sig == signal.SIGINT:
handler = signal.default_int_handler
else:
handler = signal.SIG_DFL
try:
signal.signal(sig, handler)
except OSError as exc:
if exc.errno == errno.EINVAL:
raise RuntimeError('sig {} cannot be caught'.format(sig))
else:
raise
if not self._signal_handlers:
try:
signal.set_wakeup_fd(-1)
except (ValueError, OSError) as exc:
logger.info('set_wakeup_fd(-1) failed: %s', exc)
return True
def glut_int_handler(signum, frame):
# Catch sigint and print the defautl message
signal.signal(signal.SIGINT, signal.default_int_handler)
print('\nKeyboardInterrupt')
# Need to reprint the prompt at this stage
#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------
def _allow_CTRL_C_posix():
"""Take CTRL+C into account (SIGINT)."""
signal.signal(signal.SIGINT, signal.default_int_handler)
def glut_int_handler(signum, frame):
# Catch sigint and print the defaultipyt message
signal.signal(signal.SIGINT, signal.default_int_handler)
print('\nKeyboardInterrupt')
# Need to reprint the prompt at this stage
# Initialisation code
def twistedinteract(self):
from twisted.internet import reactor
from twisted.internet.abstract import FileDescriptor
import signal
outerself = self
class Me(FileDescriptor):
def fileno(self):
""" We want to select on FD 0 """
return 0
def doRead(self):
"""called when input is ready"""
try:
outerself.handle1()
except EOFError:
reactor.stop()
reactor.addReader(Me())
reactor.callWhenRunning(signal.signal,
signal.SIGINT,
signal.default_int_handler)
self.prepare()
try:
reactor.run()
finally:
self.restore()
def worker(sock):
"""
Called by a worker process after the fork().
"""
signal.signal(SIGHUP, SIG_DFL)
signal.signal(SIGCHLD, SIG_DFL)
signal.signal(SIGTERM, SIG_DFL)
# restore the handler for SIGINT,
# it's useful for debugging (show the stacktrace before exit)
signal.signal(SIGINT, signal.default_int_handler)
# Read the socket using fdopen instead of socket.makefile() because the latter
# seems to be very slow; note that we need to dup() the file descriptor because
# otherwise writes also cause a seek that makes us miss data on the read side.
infile = os.fdopen(os.dup(sock.fileno()), "rb", 65536)
outfile = os.fdopen(os.dup(sock.fileno()), "wb", 65536)
exit_code = 0
try:
worker_main(infile, outfile)
except SystemExit as exc:
exit_code = compute_real_exit_code(exc.code)
finally:
try:
outfile.flush()
except Exception:
pass
return exit_code
def remove_signal_handler(self, sig):
"""Remove a handler for a signal. UNIX only.
Return True if a signal handler was removed, False if not.
"""
self._check_signal(sig)
try:
del self._signal_handlers[sig]
except KeyError:
return False
if sig == signal.SIGINT:
handler = signal.default_int_handler
else:
handler = signal.SIG_DFL
try:
signal.signal(sig, handler)
except OSError as exc:
if exc.errno == errno.EINVAL:
raise RuntimeError('sig {} cannot be caught'.format(sig))
else:
raise
if not self._signal_handlers:
try:
signal.set_wakeup_fd(-1)
except (ValueError, OSError) as exc:
logger.info('set_wakeup_fd(-1) failed: %s', exc)
return True
def install_shutdown_handlers(function, override_sigint=True):
"""Install the given function as a signal handler for all common shutdown
signals (such as SIGINT, SIGTERM, etc). If override_sigint is ``False`` the
SIGINT handler won't be install if there is already a handler in place
(e.g. Pdb)
"""
reactor._handleSignals()
signal.signal(signal.SIGTERM, function)
if signal.getsignal(signal.SIGINT) == signal.default_int_handler or \
override_sigint:
signal.signal(signal.SIGINT, function)
# Catch Ctrl-Break in windows
if hasattr(signal, "SIGBREAK"):
signal.signal(signal.SIGBREAK, function)
def _installSignalHandlersAgain(self):
"""
wx sometimes removes our own signal handlers, so re-add them.
"""
try:
# make _handleSignals happy:
import signal
signal.signal(signal.SIGINT, signal.default_int_handler)
except ImportError:
return
self._handleSignals()
def pytest_cmdline_main(config):
if (config.getoption('--odoo-database')
or os.environ.get('OPENERP_SERVER')):
options = []
# Replace --odoo-<something> by --<something> and prepare the argument
# to propagate to odoo.
for option in ['--odoo-database', '--odoo-log-level']:
value = config.getoption(option)
if value:
odoo_arg = '--%s' % option[7:]
options.append('%s=%s' % (odoo_arg, value))
odoo.tools.config.parse_config(options)
if not odoo.tools.config['db_name']:
# if you fall here, it means you have OPENERP_SERVER pointing
# to a configuration file without 'database' configuration
raise Exception(
"please provide a database name in the Odoo configuration file"
)
odoo.service.server.start(preload=[], stop=True)
# odoo.service.server.start() modifies the SIGINT signal by its own
# one which in fact prevents us to stop anthem with Ctrl-c.
# Restore the default one.
signal.signal(signal.SIGINT, signal.default_int_handler)
with odoo.api.Environment.manage():
yield
else:
yield
def remove_signal_handler(self, sig):
"""Remove a handler for a signal. UNIX only.
Return True if a signal handler was removed, False if not.
"""
self._check_signal(sig)
try:
del self._signal_handlers[sig]
except KeyError:
return False
if sig == signal.SIGINT:
handler = signal.default_int_handler
else:
handler = signal.SIG_DFL
try:
signal.signal(sig, handler)
except OSError as exc:
if exc.errno == errno.EINVAL:
raise RuntimeError('sig {} cannot be caught'.format(sig))
else:
raise
if not self._signal_handlers:
try:
signal.set_wakeup_fd(-1)
except (ValueError, OSError) as exc:
logger.info('set_wakeup_fd(-1) failed: %s', exc)
return True
def start(self):
while True:
try:
signal.signal(signal.SIGINT, signal.default_int_handler)
try:
#line = [i for i in input('#> ').strip().split(' ') if len(i) > 0]
line = input('#> ')
except KeyboardInterrupt:
output_manager.line_break()
continue
cmd_name = line.strip().split(' ')
if len(cmd_name) > 0 and len(cmd_name[0]) > 0:
cmd = cmd_manager.find(cmd_name[0])
if cmd.requires_smart_parse():
line = self.completer.smart_parse(line)
else:
line = self.completer.nice_split(line)
signal.signal(signal.SIGINT, sigint_handler)
cmd.execute(self.mole, line[1:] if len(line) > 1 else [])
except commands.CommandException as ex:
output_manager.error(str(ex)).line_break()
if ex.print_usage:
output_manager.normal(' Usage: {0}'.format(cmd.usage(line[0]))).line_break()
except commands.CmdNotFoundException as ex:
output_manager.error('Error: {0}'.format(ex)).line_break()
except commands.QuietCommandException:
pass
except EOFError:
output_manager.line_break()
self.mole.abort_query()
self.mole.threader.stop()
exit(0)
def setup():
# Run the SIGINT handler on SIGTERM; `svc -d` sends SIGTERM.
signal.signal(signal.SIGTERM, signal.default_int_handler)
# Ensure stdout and stderr are line-bufferred.
if not sys.stdout.line_buffering:
sys.stdout.flush()
sys.stdout = io.TextIOWrapper(
sys.stdout.buffer, sys.stdout.encoding,
line_buffering=True)
if not sys.stderr.line_buffering:
sys.stderr.flush()
sys.stderr = io.TextIOWrapper(
sys.stderr.buffer, sys.stderr.encoding,
line_buffering=True)
def glut_int_handler(signum, frame):
# Catch sigint and print the defautl message
signal.signal(signal.SIGINT, signal.default_int_handler)
print('\nKeyboardInterrupt')
# Need to reprint the prompt at this stage
#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------
def _allow_CTRL_C_posix():
"""Take CTRL+C into account (SIGINT)."""
signal.signal(signal.SIGINT, signal.default_int_handler)
def glut_int_handler(signum, frame):
# Catch sigint and print the defaultipyt message
signal.signal(signal.SIGINT, signal.default_int_handler)
print('\nKeyboardInterrupt')
# Need to reprint the prompt at this stage
# Initialisation code
def glut_int_handler(signum, frame):
# Catch sigint and print the defautl message
signal.signal(signal.SIGINT, signal.default_int_handler)
print('\nKeyboardInterrupt')
# Need to reprint the prompt at this stage
#-----------------------------------------------------------------------------
# Code
#-----------------------------------------------------------------------------
def _allow_CTRL_C_posix():
"""Take CTRL+C into account (SIGINT)."""
signal.signal(signal.SIGINT, signal.default_int_handler)