Exemplo n.º 1
0
    def _check_process_resources(self):
        """Check if the process is still is abusing resources & should continue

        This will check the processes memory usage and gracefully exit if
        it exceeds the maximum value in settings.

        :return: True if still operational, otherwise it will exit the process.
        :rtype: bool
        """
        ru_maxrss_mb = utils.ru_maxrss_mb()

        if ru_maxrss_mb < settings.DIE_ON_RESIDENT_SET_SIZE_MB:

            if self._dirty:
                # We only log when the worker has been infected by  tasks.
                logger.debug('Worker process data.')
            return True

        # Allow the client of this library to do any setup before
        # shutting down the worker.
        settings.ON_WORKER_SHUTDOWN()

        self._on_exceeding_memory_limit(ru_maxrss_mb)

        # Use non-zero exit code.
        sys.exit(1)
Exemplo n.º 2
0
 def test_other(self):
     with mock.patch.object(sys, 'platform', ''), \
         mock.patch.object(
             resource, 'getrusage', return_value=mock.Mock(ru_maxrss=2048)):
         self.assertEqual(utils.ru_maxrss_mb(), 2)
Exemplo n.º 3
0
 def test_osx(self):
     with mock.patch.object(sys, 'platform', 'darwin'), \
         mock.patch.object(
             resource, 'getrusage', return_value=mock.Mock(ru_maxrss=1024 * 1024)):
         self.assertEqual(utils.ru_maxrss_mb(), 1)