예제 #1
0
 def test_instancemethod(self):
     instance = MyObject()
     instance.attribute = 'yes'
     func = make_blocking(instance.test,
                          timeout=1,
                          gevent_friendly=self.gevent_friendly)
     func()
예제 #2
0
    def collect(self, targetdir, timestamp, delta):
        from logging import root
        from infi.blocking import make_blocking, can_use_gevent_rpc, Timeout

        # We want to copy the files in a child process, so in case the filesystem is stuck, we won't get stuck too
        kwargs = dict(dirname=self.dirname,
                      regex_basename=self.regex_basename,
                      recursive=self.recursive,
                      targetdir=path.join(targetdir, "files"),
                      timeframe_only=self.timeframe_only,
                      timestamp=timestamp,
                      delta=delta)
        try:
            [logfile_path] = [
                handler.target.baseFilename for handler in root.handlers
                if self._is_my_kind_of_logging_handler(handler)
            ] or [None]
        except ValueError:
            logfile_path = None

        func = make_blocking(self.collect_process,
                             timeout=self.timeout_in_seconds,
                             gevent_friendly=can_use_gevent_rpc())
        try:
            func(**kwargs)
        except Timeout:
            msg = "Did not finish collecting {!r} within the {} seconds timeout_in_seconds"
            logger.error(msg.format(self, self.timeout_in_seconds))
            raise TimeoutError()
예제 #3
0
    def collect(self, targetdir, timestamp, delta):
        from infi.blocking import make_blocking, can_use_gevent_rpc, Timeout
        from logging import root
        from infi.logs_collector.collectables import TimeoutError
        # We want to copy the files in a child process, so in case the filesystem is stuck, we won't get stuck too
        kwargs = dict(targetdir=targetdir, timestamp=timestamp, delta=delta)
        try:
            [logfile_path] = [handler.target.baseFilename for handler in root.handlers
            if self._is_my_kind_of_logging_handler(handler)] or [None]
        except ValueError:
            logfile_path = None

        func = make_blocking(self.collect_process, timeout=self.timeout_in_seconds, gevent_friendly=can_use_gevent_rpc())
        try:
            func(**kwargs)
        except Timeout:
            msg = "Did not finish collecting {!r} within the {} seconds timeout_in_seconds"
            logger.error(msg.format(self, self.timeout_in_seconds))
            raise TimeoutError()
예제 #4
0
 def test_nested(self):
     func = make_blocking(nested, gevent_friendly=self.gevent_friendly)
     self.assertEqual(func(5, self.gevent_friendly), self.gevent_friendly)
예제 #5
0
 def test_log_exception(self):
     make_blocking(log_exception, gevent_friendly=self.gevent_friendly)()
예제 #6
0
 def test_worker_died(self):
     func = make_blocking(suicide,
                          timeout=1,
                          gevent_friendly=self.gevent_friendly)
     with self.assertRaises(Timeout):
         func()
예제 #7
0
 def test_timeout(self):
     func = make_blocking(sleep,
                          timeout=0.1,
                          gevent_friendly=self.gevent_friendly)
     with self.assertRaises(Timeout):
         func(10)
예제 #8
0
 def test_exception(self):
     func = make_blocking(fail, gevent_friendly=self.gevent_friendly)
     with self.assertRaises(RuntimeError):
         func()
예제 #9
0
 def test_hello_world(self):
     func = make_blocking(hello_world, gevent_friendly=self.gevent_friendly)
     result = func()
     assert result == 'hello world'
예제 #10
0
def nested(level, gevent_friendly):
    if level:
        return make_blocking(nested,
                             gevent_friendly=gevent_friendly)(level - 1,
                                                              gevent_friendly)
    return gevent_friendly