Exemplo n.º 1
0
 def proxy_method(self, method, *args):
     """
     Proxy for dictionary methods called over IPC pipe.
     """
     import x84.bbs.session
     event = 'db-%s' % (self.schema,)
     session = x84.bbs.session.getsession()
     session.send_event(event, (self.table, method, args))
     return session.read_event(event)
Exemplo n.º 2
0
 def proxy_method(self, method, *args):
     """
     Proxy for dictionary methods called over IPC pipe.
     """
     import x84.bbs.session
     event = 'db-%s' % (self.schema, )
     session = x84.bbs.session.getsession()
     session.send_event(event, (self.table, method, args))
     return session.read_event(event)
Exemplo n.º 3
0
 def release(self):
     """
     Release bbs-global lock on database.
     """
     import x84.bbs.session
     event = 'lock-%s/%s' % (self.schema, self.table)
     session = x84.bbs.session.getsession()
     return session.send_event(event, ('release', None))
Exemplo n.º 4
0
 def proxy_iter(self, method, *args):
     """
     Iterable proxy for dictionary methods called over IPC pipe.
     """
     import x84.bbs.session
     event = 'db=%s' % (self.schema, )
     session = x84.bbs.session.getsession()
     session.flush_event(event)
     session.send_event(event, (self.table, method, args))
     data = session.read_event(event)
     assert data == (None, 'StartIteration'), (
         'iterable proxy used on non-iterable, %r' % (data, ))
     data = session.read_event(event)
     while data != (None, StopIteration):
         yield data
         data = session.read_event(event)
     session.flush_event(event)
Exemplo n.º 5
0
 def release(self):
     """
     Release bbs-global lock on database.
     """
     import x84.bbs.session
     event = 'lock-%s/%s' % (self.schema, self.table)
     session = x84.bbs.session.getsession()
     return session.send_event(event, ('release', None))
Exemplo n.º 6
0
 def proxy_iter(self, method, *args):
     """
     Iterable proxy for dictionary methods called over IPC pipe.
     """
     import x84.bbs.session
     event = 'db=%s' % (self.schema,)
     session = x84.bbs.session.getsession()
     session.flush_event(event)
     session.send_event(event, (self.table, method, args))
     data = session.read_event(event)
     assert data == (None, 'StartIteration'), (
         'iterable proxy used on non-iterable, %r' % (data,))
     data = session.read_event(event)
     while data != (None, StopIteration):
         yield data
         data = session.read_event(event)
     session.flush_event(event)
Exemplo n.º 7
0
    def acquire(self, blocking=False):
        """
        Acquire a fine-grained BBS-global lock, blocking or non-blocking.

        When invoked with the blocking argument set to True (the default),
        block until the lock is acquired, and return True.

        When invoked with the blocking argument set to False, do not block.
        Returns False if lock is not acquired.
        """
        import x84.bbs.session
        event = 'lock-%s/%s' % (self.schema, self.table)
        session = x84.bbs.session.getsession()
        while True:
            session.send_event(event, ('acquire', True))
            if session.read_event(event):
                return True
            if not blocking:
                return False
            time.sleep(0.1)
Exemplo n.º 8
0
    def acquire(self, blocking=True, stale=2.0):
        """
        Acquire a fine-grained BBS-global lock, blocking or non-blocking.

        When invoked with the blocking argument set to True (the default),
        block until the lock is acquired, and return True.

        When invoked with the blocking argument set to False, do not block.
        Returns False if lock is not acquired.

        If the engine has held the lock longer than ``stale`` seconds, the
        lock is granted anyway.
        """
        import x84.bbs.session
        event = 'lock-%s/%s' % (self.schema, self.table)
        session = x84.bbs.session.getsession()
        while True:
            session.send_event(event, ('acquire', stale))
            data = session.read_event(event)
            if data is True or not blocking:
                return data
            time.sleep(0.1)
Exemplo n.º 9
0
    def acquire(self, blocking=True, stale=2.0):
        """
        Acquire a fine-grained BBS-global lock, blocking or non-blocking.

        When invoked with the blocking argument set to True (the default),
        block until the lock is acquired, and return True.

        When invoked with the blocking argument set to False, do not block.
        Returns False if lock is not acquired.

        If the engine has held the lock longer than ``stale`` seconds, the
        lock is granted anyway.
        """
        import x84.bbs.session
        event = 'lock-%s/%s' % (self.schema, self.table)
        session = x84.bbs.session.getsession()
        while True:
            session.send_event(event, ('acquire', stale))
            data = session.read_event(event)
            if data is True or not blocking:
                return data
            time.sleep(0.1)