예제 #1
0
 def testInterval(self):
     
     count = []
     def ival():
         count.append(1) 
     
     #test non immediate    
     ival_task = Tasklet.interval(1.0, ival, False)()
         
     try:
         Tasklet.join(ival_task, 3.0)
     except TimeoutError:
         #expect 2 counts, because interval started after 1 second
         self.assertEquals(2, len(count))
     except:
         self.fail('expected timeout, got %s' % sys.exc_type)
     finally:
         ival_task.kill()
         
     #test immediate
     count = []
     ival_task = Tasklet.interval(1.0, ival, True)()
         
     try:
         Tasklet.join(ival_task, 3.0)
     except TimeoutError:
         #expect 3 counts, because interval started immediately
         self.assertEquals(3, len(count))
     except:
         self.fail('expected timeout')
     finally:
         ival_task.kill()
예제 #2
0
    def testInterval(self):

        count = []

        def ival():
            count.append(1)

        #test non immediate
        ival_task = Tasklet.interval(1.0, ival, False)()

        try:
            Tasklet.join(ival_task, 3.0)
        except TimeoutError:
            #expect 2 counts, because interval started after 1 second
            self.assertEquals(2, len(count))
        except:
            self.fail('expected timeout, got %s' % sys.exc_type)
        finally:
            ival_task.kill()

        #test immediate
        count = []
        ival_task = Tasklet.interval(1.0, ival, True)()

        try:
            Tasklet.join(ival_task, 3.0)
        except TimeoutError:
            #expect 3 counts, because interval started immediately
            self.assertEquals(3, len(count))
        except:
            self.fail('expected timeout')
        finally:
            ival_task.kill()
예제 #3
0
 def run(self):
     #show stats every second:
     Tasklet.interval(1.0, self.show, immediate = True)()
     
     #dispenses tokens for doing a request to sessions:
     Tasklet.new(self.dispense)()
     
     #start up sessions, and wait till they are finished
     Tasklet.join_all([Tasklet.new(self.sessions)() for _ in range(self.options.sessions)])
     
     quit()
예제 #4
0
    def __init__(self,
                 connector,
                 dbargs,
                 max_connections=10,
                 connect_timeout=-1,
                 max_connection_age=None,
                 max_connection_age_reaper_interval=60):
        super(Pool, self).__init__(connector, dbargs, connect_timeout)

        self._max_connections = max_connections
        self._max_connection_age = max_connection_age

        #some statistics
        self._queue_wait_timer_statistic = StatisticExtra()
        self._queue_wait_tasks_statistic = StatisticExtra()

        self._pool = Deque()  #the pool of available idle connections

        #watch for server disconnects on idle connections:
        self._idle_disconnect_channel = Channel()
        self._idle_disconnect_reaper_task = Tasklet.loop(
            self._idle_disconnect_reaper, daemon=True)()

        #check for old connections
        if self._max_connection_age is not None:
            self._old_connection_reaper_task = Tasklet.interval(
                max_connection_age_reaper_interval,
                self._old_connection_reaper,
                daemon=True)()
예제 #5
0
파일: pool.py 프로젝트: JoyTeam/concurrence
    def __init__(
        self,
        connector,
        dbargs,
        max_connections=10,
        connect_timeout=TIMEOUT_CURRENT,
        max_connection_age=None,
        max_connection_age_reaper_interval=60,
    ):
        super(Pool, self).__init__(connector, dbargs, connect_timeout)

        self._max_connections = max_connections
        self._max_connection_age = max_connection_age

        # some statistics
        self._queue_wait_timer_statistic = StatisticExtra()
        self._queue_wait_tasks_statistic = StatisticExtra()

        self._pool = Deque()  # the pool of available idle connections

        # check for old connections
        if self._max_connection_age is not None:
            self._old_connection_reaper_task = Tasklet.interval(
                max_connection_age_reaper_interval, self._old_connection_reaper, daemon=True
            )()
예제 #6
0
 def __init__(self, connector, dbargs, max_connections = 10, connect_timeout = -1, max_connection_age = None,
              max_connection_age_reaper_interval = 60):
     super(Pool, self).__init__(connector, dbargs, connect_timeout)
     
     self._max_connections = max_connections
     self._max_connection_age = max_connection_age
     
     #some statistics        
     self._queue_wait_timer_statistic = StatisticExtra()
     self._queue_wait_tasks_statistic = StatisticExtra()        
     
     self._pool = Deque() #the pool of available idle connections
             
     #watch for server disconnects on idle connections:
     self._idle_disconnect_channel = Channel()
     self._idle_disconnect_reaper_task = Tasklet.loop(self._idle_disconnect_reaper, daemon = True)()
     
     #check for old connections
     if self._max_connection_age is not None:
         self._old_connection_reaper_task = Tasklet.interval(max_connection_age_reaper_interval, 
                                                             self._old_connection_reaper, daemon = True)()
예제 #7
0
    def __init__(self,
                 connector,
                 dbargs,
                 max_connections=10,
                 connect_timeout=TIMEOUT_CURRENT,
                 max_connection_age=None,
                 max_connection_age_reaper_interval=60):
        super(Pool, self).__init__(connector, dbargs, connect_timeout)

        self._max_connections = max_connections
        self._max_connection_age = max_connection_age

        #some statistics
        self._queue_wait_timer_statistic = StatisticExtra()
        self._queue_wait_tasks_statistic = StatisticExtra()

        self._pool = Deque()  #the pool of available idle connections

        #check for old connections
        if self._max_connection_age is not None:
            self._old_connection_reaper_task = Tasklet.interval(
                max_connection_age_reaper_interval,
                self._old_connection_reaper,
                daemon=True)()