sys.exitfunc

Here are the examples of the python api sys.exitfunc taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

25 Examples 7

Example 1

Project: pymo
Source File: run.py
View license
def exit():
    """Exit subprocess, possibly after first deleting sys.exitfunc

    If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any
    sys.exitfunc will be removed before exiting.  (VPython support)

    """
    if no_exitfunc:
        try:
            del sys.exitfunc
        except AttributeError:
            pass
    sys.exit(0)

Example 2

Project: pymo
Source File: test_atexit.py
View license
    def test_sys_override(self):
        # be sure a preset sys.exitfunc is handled properly
        exfunc = sys.exitfunc
        sys.exitfunc = self.h1
        reload(atexit)
        try:
            atexit.register(self.h2)
            atexit._run_exitfuncs()
        finally:
            sys.exitfunc = exfunc
        self.assertEqual(self.subst_io.getvalue(), "h2\nh1\n")

Example 3

Project: imagrium
Source File: test_atexit.py
View license
    def test_sys_override(self):
        # be sure a preset sys.exitfunc is handled properly
        exfunc = sys.exitfunc
        sys.exitfunc = self.h1
        reload(atexit)
        try:
            atexit.register(self.h2)
            atexit._run_exitfuncs()
        finally:
            sys.exitfunc = exfunc
        self.assertEqual(self.subst_io.getvalue(), "h2\nh1\n")

Example 4

Project: WAPT
Source File: run.py
View license
def exit():
    """Exit subprocess, possibly after first deleting sys.exitfunc

    If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any
    sys.exitfunc will be removed before exiting.  (VPython support)

    """
    if no_exitfunc:
        try:
            del sys.exitfunc
        except AttributeError:
            pass
    capture_warnings(False)
    sys.exit(0)

Example 5

Project: chipsec
Source File: test_atexit.py
View license
    def test_sys_override(self):
        # be sure a preset sys.exitfunc is handled properly
        exfunc = sys.exitfunc
        sys.exitfunc = self.h1
        reload(atexit)
        try:
            atexit.register(self.h2)
            atexit._run_exitfuncs()
        finally:
            sys.exitfunc = exfunc
        self.assertEqual(self.subst_io.getvalue(), "h2\nh1\n")

Example 6

Project: datafari
Source File: run.py
View license
def exit():
    """Exit subprocess, possibly after first deleting sys.exitfunc

    If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any
    sys.exitfunc will be removed before exiting.  (VPython support)

    """
    if no_exitfunc:
        try:
            del sys.exitfunc
        except AttributeError:
            pass
    capture_warnings(False)
    sys.exit(0)

Example 7

Project: datafari
Source File: test_atexit.py
View license
    def test_sys_override(self):
        # be sure a preset sys.exitfunc is handled properly
        exfunc = sys.exitfunc
        sys.exitfunc = self.h1
        reload(atexit)
        try:
            atexit.register(self.h2)
            atexit._run_exitfuncs()
        finally:
            sys.exitfunc = exfunc
        self.assertEqual(self.subst_io.getvalue(), "h2\nh1\n")

Example 8

Project: openwrt-mt7620
Source File: run.py
View license
def exit():
    """Exit subprocess, possibly after first deleting sys.exitfunc

    If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any
    sys.exitfunc will be removed before exiting.  (VPython support)

    """
    if no_exitfunc:
        try:
            del sys.exitfunc
        except AttributeError:
            pass
    sys.exit(0)

Example 9

Project: openwrt-mt7620
Source File: test_atexit.py
View license
    def test_sys_override(self):
        # be sure a preset sys.exitfunc is handled properly
        exfunc = sys.exitfunc
        sys.exitfunc = self.h1
        reload(atexit)
        try:
            atexit.register(self.h2)
            atexit._run_exitfuncs()
        finally:
            sys.exitfunc = exfunc
        self.assertEqual(self.subst_io.getvalue(), "h2\nh1\n")

Example 10

Project: openwrt-mt7620
Source File: run.py
View license
def exit():
    """Exit subprocess, possibly after first deleting sys.exitfunc

    If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any
    sys.exitfunc will be removed before exiting.  (VPython support)

    """
    if no_exitfunc:
        try:
            del sys.exitfunc
        except AttributeError:
            pass
    sys.exit(0)

Example 11

Project: openwrt-mt7620
Source File: test_atexit.py
View license
    def test_sys_override(self):
        # be sure a preset sys.exitfunc is handled properly
        exfunc = sys.exitfunc
        sys.exitfunc = self.h1
        reload(atexit)
        try:
            atexit.register(self.h2)
            atexit._run_exitfuncs()
        finally:
            sys.exitfunc = exfunc
        self.assertEqual(self.subst_io.getvalue(), "h2\nh1\n")

Example 12

Project: neuroConstruct
Source File: test_atexit.py
View license
    def test_sys_override(self):
        # be sure a preset sys.exitfunc is handled properly
        exfunc = sys.exitfunc
        sys.exitfunc = self.h1
        reload(atexit)
        try:
            atexit.register(self.h2)
            atexit._run_exitfuncs()
        finally:
            sys.exitfunc = exfunc
        self.assertEqual(self.subst_io.getvalue(), "h2\nh1\n")

Example 13

Project: neuroConstruct
Source File: test_atexit.py
View license
    def test_sys_override(self):
        # be sure a preset sys.exitfunc is handled properly
        exfunc = sys.exitfunc
        sys.exitfunc = self.h1
        reload(atexit)
        try:
            atexit.register(self.h2)
            atexit._run_exitfuncs()
        finally:
            sys.exitfunc = exfunc
        self.assertEqual(self.subst_io.getvalue(), "h2\nh1\n")

Example 14

Project: PyAutoC
Source File: run.py
View license
def exit():
    """Exit subprocess, possibly after first deleting sys.exitfunc

    If config-main.cfg/.def 'General' 'delete-exitfunc' is True, then any
    sys.exitfunc will be removed before exiting.  (VPython support)

    """
    if no_exitfunc:
        try:
            del sys.exitfunc
        except AttributeError:
            pass
    sys.exit(0)

Example 15

Project: PyAutoC
Source File: test_atexit.py
View license
    def test_sys_override(self):
        # be sure a preset sys.exitfunc is handled properly
        exfunc = sys.exitfunc
        sys.exitfunc = self.h1
        reload(atexit)
        try:
            atexit.register(self.h2)
            atexit._run_exitfuncs()
        finally:
            sys.exitfunc = exfunc
        self.assertEqual(self.subst_io.getvalue(), "h2\nh1\n")

Example 16

Project: django-dockit
Source File: setuptest.py
View license
def runtests():
    """Test runner for setup.py test."""
    # Run you some tests.
    import django.test.utils
    runner_class = django.test.utils.get_runner(settings)
    test_runner = runner_class(verbosity=1, interactive=True)
    failures = test_runner.run_tests(['dockit'])

    # Okay, so this is a nasty hack. If this isn't here, `setup.py test` craps out
    # when generating a coverage report via Nose. I have no idea why, or what's
    # supposed to be going on here, but this seems to fix the problem, and I
    # *really* want coverage, so, unless someone can tell me *why* I shouldn't
    # do this, I'm going to just whistle innocently and keep on doing this.
    sys.exitfunc = lambda: 0

    sys.exit(failures)

Example 17

Project: django-hyperadmin
Source File: runtests.py
View license
def runtests():
    """Test runner for setup.py test."""
    # Run you some tests.
    import django.test.utils
    runner_class = django.test.utils.get_runner(settings)
    test_runner = runner_class(verbosity=1, interactive=True)
    failures = test_runner.run_tests(['hyperadmin'])

    # Okay, so this is a nasty hack. If this isn't here, `setup.py test` craps out
    # when generating a coverage report via Nose. I have no idea why, or what's
    # supposed to be going on here, but this seems to fix the problem, and I
    # *really* want coverage, so, unless someone can tell me *why* I shouldn't
    # do this, I'm going to just whistle innocently and keep on doing this.
    sys.exitfunc = lambda: 0

    sys.exit(failures)

Example 18

Project: django-haystack
Source File: run_tests.py
View license
def run_all(argv=None):
    sys.exitfunc = lambda: sys.stderr.write('Shutting down....\n')

    # always insert coverage when running tests through setup.py
    if argv is None:
        argv = [
            'nosetests', '--with-coverage', '--cover-package=haystack',
            '--cover-erase', '--verbose',
        ]

    nose.run_exit(
        argv=argv,
        defaultTest=abspath(dirname(__file__))
    )

Example 19

Project: elasticsearch-py
Source File: run_tests.py
View license
def run_all(argv=None):
    sys.exitfunc = lambda: sys.stderr.write('Shutting down....\n')

    # fetch yaml tests
    fetch_es_repo()

    # always insert coverage when running tests
    if argv is None:
        argv = [
            'nosetests', '--with-xunit',
            '--with-xcoverage', '--cover-package=elasticsearch', '--cover-erase',
            '--logging-filter=elasticsearch', '--logging-level=DEBUG',
            '--verbose',
        ]

    nose.run_exit(
        argv=argv,
        defaultTest=abspath(dirname(__file__))
    )

Example 20

Project: ella
Source File: run_tests.py
View license
def run_all(argv=None):
    os.environ['DJANGO_SETTINGS_MODULE'] = 'test_ella.settings'
    sys.exitfunc = lambda msg='Process shutting down...': sys.stderr.write(msg + '\n')

    # called by setuptools
    if argv is None:
        argv = ['nosetests']

    if len(argv) == 1:  # only the command itself is in argv
        argv += [
            '--with-coverage', '--cover-package=ella', '--cover-erase',
            '--with-xunit',
        ]

    nose.run_exit(
        argv=argv,
        defaultTest=abspath(dirname(__file__)),
    )

Example 21

Project: bib
Source File: runtests.py
View license
def start(argv=None):
    sys.exitfunc = lambda: sys.stderr.write("Shutting down...\n")

    if argv is None:
        argv = [
            "nosetests", "--cover-branches", "--with-coverage",
            "--cover-erase", "--verbose",
            "--cover-package=bib",
        ]

    nose.run_exit(argv=argv, defaultTest=os.path.abspath(os.path.dirname(__file__)))

Example 22

Project: drf-haystack
Source File: runtests.py
View license
def start(argv=None):
    sys.exitfunc = lambda: sys.stderr.write("Shutting down...\n")

    if argv is None:
        argv = [
            "nosetests",
            "--verbose",
            "--with-coverage",
            "--cover-erase",
            "--cover-branches",
            "--cover-package=drf_haystack",
        ]

    nose.run_exit(argv=argv, defaultTest=os.path.abspath(os.path.dirname(__file__)))

Example 23

Project: django-storymarket
Source File: runtests.py
View license
def runtests():
    """Test runner for setup.py test."""
    # Run you some tests.
    import django.test.utils
    runner_class = django.test.utils.get_runner(settings)
    test_runner = runner_class(verbosity=1, interactive=True)
    failures = test_runner.run_tests(['django_storymarket'])
    
    # Okay, so this is a nasty hack. If this isn't here, `setup.py test` craps out
    # when generating a coverage report via Nose. I have no idea why, or what's
    # supposed to be going on here, but this seems to fix the problem, and I
    # *really* want coverage, so, unless someone can tell me *why* I shouldn't
    # do this, I'm going to just whistle innocently and keep on doing this.
    sys.exitfunc = lambda: 0
    
    sys.exit(failures)

Example 24

Project: music-player
Source File: gui.py
View license
def handleApplicationQuit():
	"""
	Depending on the environment, this might be called multiple times.
	It should do some cleanup and save the DBs and such.

	Once this get called, the app is not expected to be in a
	functional state anymore.
	
	This is normally registerd via `atexit.register()` in `main()`.
	"""

	# Call sys.exitfunc() manually here now to ensure that we
	# handled all that.
	sysExitFunc, sys.exitfunc = sys.exitfunc, None
	sysExitFunc()

	import utils
	if utils.quit > 1: return # Already called before.
	utils.quit = 1

	# first set/send signals to all modules
	from ModuleSystem import modules
	for m in modules: m.stop(join=False)
	try:
		# in case there are any subprocesses, interrupt them
		# maybe some modules are hanging and waiting for such
		import sys, os, signal
		os.kill(0, signal.SIGINT)
	except KeyboardInterrupt: pass # well, we expect that...
	except Exception: pass

	# now join all
	for m in modules: m.stop()

	# Do some cleanup before we let Python do the final cleanup.
	# E.g., it might happen that Python will not GC the player instance
	# soon enough in its `Py_Finalize()`. In that situation, bad things
	# will happen, because most probably, the player instances worker
	# thread is still running in the background. This most probably
	# leads to a crash.
	RootObjs.clear()
	try: ctx().rootObjs.clear()
	except Exception: pass # might already be out of scope
	import State
	State.state = None
	import gc
	for _ in range(3): gc.collect()

	utils.quit = 2
	print "Bye!"

Example 25

Project: exaproxy
Source File: supervisor.py
View license
	def __init__ (self,configuration):
		self.configuration = configuration

		# Only here so the introspection code can find them
		self.log = Logger('supervisor', configuration.log.supervisor)
		self.log.error('Starting exaproxy version %s' % configuration.proxy.version)

		self.signal_log = Logger('signal', configuration.log.signal)
		self.log_writer = SysLogWriter('log', configuration.log.destination, configuration.log.enable, level=configuration.log.level)
		self.usage_writer = UsageWriter('usage', configuration.usage.destination, configuration.usage.enable)

		sys.exitfunc = self.log_writer.writeMessages

		self.log_writer.setIdentifier(configuration.daemon.identifier)
		#self.usage_writer.setIdentifier(configuration.daemon.identifier)

		if configuration.debug.log:
			self.log_writer.toggleDebug()
			self.usage_writer.toggleDebug()

		self.log.error('python version %s' % sys.version.replace(os.linesep,' '))
		self.log.debug('starting %s' % sys.argv[0])

		self.pid = PID(self.configuration)

		self.daemon = Daemon(self.configuration)
		self.poller = Poller(self.configuration.daemon)

		self.poller.setupRead('read_proxy')       # Listening proxy sockets
		self.poller.setupRead('read_web')         # Listening webserver sockets
		self.poller.setupRead('read_icap')        # Listening icap sockets
		self.poller.setupRead('read_tls')         # Listening tls sockets
		self.poller.setupRead('read_passthrough') # Listening raw data sockets
		self.poller.setupRead('read_redirector')  # Pipes carrying responses from the redirector process
		self.poller.setupRead('read_resolver')    # Sockets currently listening for DNS responses

		self.poller.setupRead('read_client')      # Active clients
		self.poller.setupRead('opening_client')   # Clients we have not yet read a request from
		self.poller.setupWrite('write_client')    # Active clients with buffered data to send
		self.poller.setupWrite('write_resolver')  # Active DNS requests with buffered data to send

		self.poller.setupRead('read_download')      # Established connections
		self.poller.setupWrite('write_download')    # Established connections we have buffered data to send to
		self.poller.setupWrite('opening_download')  # Opening connections

		self.poller.setupRead('read_interrupt')		# Scheduled events
		self.poller.setupRead('read_control')		# Responses from commands sent to the redirector process

		self.monitor = Monitor(self)
		self.page = Page(self)
		self.content = ContentManager(self,configuration)
		self.client = ClientManager(self.poller, configuration)
		self.resolver = ResolverManager(self.poller, self.configuration, configuration.dns.retries*10)
		self.proxy = Server('http proxy',self.poller,'read_proxy', configuration.http)
		self.web = Server('web server',self.poller,'read_web', configuration.web)
		self.icap = Server('icap server',self.poller,'read_icap', configuration.icap)
		self.tls = Server('tls server', self.poller, 'read_tls', configuration.tls)
		self.passthrough = InterceptServer('passthrough server', self.poller, 'read_passthrough', configuration.passthrough)

		self._shutdown = True if self.daemon.filemax == 0 else False  # stop the program
		self._softstop = False  # stop once all current connection have been dealt with
		self._reload = False  # unimplemented
		self._toggle_debug = False  # start logging a lot
		self._decrease_spawn_limit = 0
		self._increase_spawn_limit = 0
		self._refork = False  # unimplemented
		self._pdb = False  # turn on pdb debugging
		self._listen = None  # listening change ? None: no, True: listen, False: stop listeing
		self.wait_time = 5.0  # how long do we wait at maximum once we have been soft-killed
		self.local = set()  # what addresses are on our local interfaces

		if not self.initialise():
			self._shutdown = True

		elif self.daemon.drop_privileges():
			self.log.critical('Could not drop privileges to \'%s\'. Refusing to run as root' % self.daemon.user)
			self.log.critical('Set the environment value USER to change the unprivileged user')
			self._shutdown = True


		# fork the redirector process before performing any further setup
		redirector = fork_redirector(self.poller, self.configuration)

		# use simple blocking IO for communication with the redirector process
		self.redirector = redirector_message_thread(redirector)


		# NOTE: create threads _after_ all forking is done

		# regularly interrupt the reactor for maintenance
		self.interrupt_scheduler = alarm_thread(self.poller, self.alarm_time)

		self.reactor = Reactor(self.configuration, self.web, self.proxy, self.passthrough, self.icap, self.tls, self.redirector, self.content, self.client, self.resolver, self.log_writer, self.usage_writer, self.poller)

		self.interfaces()

		signal.signal(signal.SIGQUIT, self.sigquit)
		signal.signal(signal.SIGINT, self.sigterm)
		signal.signal(signal.SIGTERM, self.sigterm)
		# signal.signal(signal.SIGABRT, self.sigabrt)
		# signal.signal(signal.SIGHUP, self.sighup)

		signal.signal(signal.SIGTRAP, self.sigtrap)

		signal.signal(signal.SIGUSR1, self.sigusr1)
		signal.signal(signal.SIGUSR2, self.sigusr2)
		signal.signal(signal.SIGTTOU, self.sigttou)
		signal.signal(signal.SIGTTIN, self.sigttin)

		# make sure we always have data in history
		# (done in zero for dependencies reasons)

		if self._shutdown is False:
			self.redirector.requestStats()
			command, control_data = self.redirector.readResponse()
			stats_data = control_data if command == 'STATS' else None

			stats = self.monitor.statistics(stats_data)
			ok = self.monitor.zero(stats)

			if ok:
				self.redirector.requestStats()

			else:
				self._shutdown = True