Example #1
0
 def __init__(self, pull_info, packet, server):
     Greenlet.__init__(self)
     self.ps = db6.pubsub()
     self.server = server
     self.packet = packet
     self.pull_info = pull_info
     self.token = packet[1:3]
Example #2
0
 def __init__(self, db, collection, doc, act):
     # super(greenlet, self).__init__()
     Greenlet.__init__(self)
     self.db = db
     self.collection = collection
     self.doc = doc
     self.act = act
Example #3
0
 def __init__(self, stats, reader_clients, event_push_client):
     Greenlet.__init__(self)
     self._log = logging.getLogger(str(self))
     self._stats = stats
     self._reader_clients = reader_clients
     self._event_push_client = event_push_client
     self._halt_event = Event()
    def __init__(self, ctx, manager, config, fs, max_mds):
        Greenlet.__init__(self)

        self.config = config
        self.ctx = ctx
        self.e = None
        self.logger = log.getChild('fs.[{f}]'.format(f=fs.name))
        self.fs = fs
        self.manager = manager
        self.max_mds = max_mds
        self.name = 'thrasher.fs.[{f}]'.format(f=fs.name)
        self.stopping = Event()

        self.randomize = bool(self.config.get('randomize', True))
        self.thrash_max_mds = float(self.config.get('thrash_max_mds', 0.0))
        self.max_thrash = int(self.config.get('max_thrash', 1))
        self.max_thrash_delay = float(self.config.get('thrash_delay', 120.0))
        self.thrash_in_replay = float(
            self.config.get('thrash_in_replay', False))
        assert self.thrash_in_replay >= 0.0 and self.thrash_in_replay <= 1.0, 'thrash_in_replay ({v}) must be between [0.0, 1.0]'.format(
            v=self.thrash_in_replay)
        self.max_replay_thrash_delay = float(
            self.config.get('max_replay_thrash_delay', 4.0))
        self.max_revive_delay = float(self.config.get('max_revive_delay',
                                                      10.0))
Example #5
0
 def __init__(self, address, locals=None):
     Greenlet.__init__(self)
     if isinstance(address, socket.socket):
         self.socket = address
     else:
         self.socket = socket.tcp_listener(address)
     self.locals = locals
    def __init__(
        self,
        context,
        server_node_name,
        server_address,
        client_tag,
        client_address,
        deliverator,
        connect_messages=list(),
    ):
        Greenlet.__init__(self)

        self._log = logging.getLogger("ResilientClient-%s" % (server_address,))

        self._context = context
        self._server_node_name = server_node_name
        self._server_address = server_address

        self._client_tag = client_tag
        self._client_address = client_address
        self._deliverator = deliverator

        self._send_queue = gevent.queue.Queue()

        # prime the send queue with messages to be sent as soon
        # as we connect
        for connect_message in connect_messages:
            if not "message-id" in connect_message:
                connect_message["message-id"] = uuid.uuid1().hex
            message = message_format(ident=None, control=connect_message, body=None)
            self._send_queue.put(message)

        self._req_socket = None
        self.connected = False
Example #7
0
 def __init__(self, address, locals=None):
     Greenlet.__init__(self)
     if isinstance(address, socket.socket):
         self.socket = address
     else:
         self.socket = socket.tcp_listener(address)
     self.locals = locals
Example #8
0
 def __init__(self, stats, reader_clients, event_push_client):
     Greenlet.__init__(self)
     self._log = logging.getLogger(str(self))
     self._stats = stats
     self._reader_clients = reader_clients
     self._event_push_client = event_push_client
     self._halt_event = Event()
Example #9
0
 def __init__(self, *args, **kwargs):
     Greenlet.__init__(self, *args, **kwargs)
     self.stdin = None
     self.stdout = None
     self.prev_stdin = None
     self.prev_stdout = None
     self.prev_stderr = None
Example #10
0
    def __init__(self,
                 func,
                 iterable,
                 spawn=None,
                 maxsize=None,
                 _zipped=False):
        """
        An iterator that.

        :keyword int maxsize: If given and not-None, specifies the maximum number of
            finished results that will be allowed to accumulated awaiting the reader;
            more than that number of results will cause map function greenlets to begin
            to block. This is most useful is there is a great disparity in the speed of
            the mapping code and the consumer and the results consume a great deal of resources.
            Using a bound is more computationally expensive than not using a bound.

        .. versionchanged:: 1.1b3
            Added the *maxsize* parameter.
        """
        from gevent.queue import Queue
        Greenlet.__init__(self)
        if spawn is not None:
            self.spawn = spawn
        if _zipped:
            self._zipped = _zipped
        self.func = func
        self.iterable = iterable
        self.queue = Queue()
        if maxsize:
            # Bounding the queue is not enough if we want to keep from
            # accumulating objects; the result value will be around as
            # the greenlet's result, blocked on self.queue.put(), and
            # we'll go on to spawn another greenlet, which in turn can
            # create the result. So we need a semaphore to prevent a
            # greenlet from exiting while the queue is full so that we
            # don't spawn the next greenlet (assuming that self.spawn
            # is of course bounded). (Alternatively we could have the
            # greenlet itself do the insert into the pool, but that
            # takes some rework).
            #
            # Given the use of a semaphore at this level, sizing the queue becomes
            # redundant, and that lets us avoid having to use self.link() instead
            # of self.rawlink() to avoid having blocking methods called in the
            # hub greenlet.
            self._result_semaphore = Semaphore(maxsize)
        else:
            self._result_semaphore = DummySemaphore()
        self.count = 0
        self.finished = False
        # If the queue size is unbounded, then we want to call all
        # the links (_on_finish and _on_result) directly in the hub greenlet
        # for efficiency. However, if the queue is bounded, we can't do that if
        # the queue might block (because if there's no waiter the hub can switch to,
        # the queue simply raises Full). Therefore, in that case, we use
        # the safer, somewhat-slower (because it spawns a greenlet) link() methods.
        # This means that _on_finish and _on_result can be called and interleaved in any order
        # if the call to self.queue.put() blocks..
        # Note that right now we're not bounding the queue, instead using a semaphore.
        self.rawlink(self._on_finish)
Example #11
0
 def __init__(self, spawn, func, iterable):
     from gevent.queue import Queue
     Greenlet.__init__(self)
     self.spawn = spawn
     self.func = func
     self.iterable = iterable
     self.queue = Queue()
     self.count = 0
Example #12
0
 def __init__(self, item, server):
     Greenlet.__init__(self)
     dev_eui = unhexlify(item['channel'].decode().replace(
         Channel1.join_accept_alarm, ''))
     accept = item['data'].decode()
     self.server = server
     self.dev_eui = dev_eui
     self.data = accept
Example #13
0
 def __init__(self, spawn, func, iterable):
     from gevent.queue import Queue
     Greenlet.__init__(self)
     self.spawn = spawn
     self.func = func
     self.iterable = iterable
     self.queue = Queue()
     self.count = 0
Example #14
0
 def __init__(self, sock, service=None, close_callback=None):
     self._buff = ""
     self.sock = sock
     self._timeout = 10  # 请求超时时间
     self._id_iter = _id_generator()  # 消息id生成器
     self._request_table = {}  # 保存所有的RPC请求的AsyncResult,key对应包ID,范围为30bit,在timeout时间内,理论上不可能重复
     self.service = service
     self.close_callback = close_callback  # 断开毁掉
     Greenlet.__init__(self)
Example #15
0
    def __init__(self, func, iterable, spawn=None, maxsize=None, _zipped=False):
        """
        An iterator that.

        :keyword int maxsize: If given and not-None, specifies the maximum number of
            finished results that will be allowed to accumulated awaiting the reader;
            more than that number of results will cause map function greenlets to begin
            to block. This is most useful is there is a great disparity in the speed of
            the mapping code and the consumer and the results consume a great deal of resources.
            Using a bound is more computationally expensive than not using a bound.

        .. versionchanged:: 1.1b3
            Added the *maxsize* parameter.
        """
        from gevent.queue import Queue
        Greenlet.__init__(self)
        if spawn is not None:
            self.spawn = spawn
        if _zipped:
            self._zipped = _zipped
        self.func = func
        self.iterable = iterable
        self.queue = Queue()
        if maxsize:
            # Bounding the queue is not enough if we want to keep from
            # accumulating objects; the result value will be around as
            # the greenlet's result, blocked on self.queue.put(), and
            # we'll go on to spawn another greenlet, which in turn can
            # create the result. So we need a semaphore to prevent a
            # greenlet from exiting while the queue is full so that we
            # don't spawn the next greenlet (assuming that self.spawn
            # is of course bounded). (Alternatively we could have the
            # greenlet itself do the insert into the pool, but that
            # takes some rework).
            #
            # Given the use of a semaphore at this level, sizing the queue becomes
            # redundant, and that lets us avoid having to use self.link() instead
            # of self.rawlink() to avoid having blocking methods called in the
            # hub greenlet.
            factory = Semaphore
        else:
            factory = DummySemaphore
        self._result_semaphore = factory(maxsize)

        self.count = 0
        self.finished = False
        # If the queue size is unbounded, then we want to call all
        # the links (_on_finish and _on_result) directly in the hub greenlet
        # for efficiency. However, if the queue is bounded, we can't do that if
        # the queue might block (because if there's no waiter the hub can switch to,
        # the queue simply raises Full). Therefore, in that case, we use
        # the safer, somewhat-slower (because it spawns a greenlet) link() methods.
        # This means that _on_finish and _on_result can be called and interleaved in any order
        # if the call to self.queue.put() blocks..
        # Note that right now we're not bounding the queue, instead using a semaphore.
        self.rawlink(self._on_finish)
Example #16
0
 def __init__(self, func, iterable, spawn=None):
     from gevent.queue import Queue
     Greenlet.__init__(self)
     if spawn is not None:
         self.spawn = spawn
     self.func = func
     self.iterable = iterable
     self.queue = Queue()
     self.count = 0
     self.rawlink(self._on_finish)
 def __init__(self, func, iterable, spawn=None):
     from gevent.queue import Queue
     Greenlet.__init__(self)
     if spawn is not None:
         self.spawn = spawn
     self.func = func
     self.iterable = iterable
     self.queue = Queue()
     self.count = 0
     self.rawlink(self._on_finish)
Example #18
0
 def __init__(self, ctx, manager, config, thrashers):
     Greenlet.__init__(self)
     self.ctx = ctx
     self.config = config
     self.e = None
     self.logger = log.getChild('daemon_watchdog')
     self.manager = manager
     self.name = 'watchdog'
     self.stopping = Event()
     self.thrashers = thrashers
Example #19
0
 def __init__(self, sock, service=None, close_callback=None):
     self._buff = ''
     self.sock = sock
     self._timeout = 10  # 请求超时时间
     self._id_iter = _id_generator()  # 消息id生成器
     self._request_table = {
     }  # 保存所有的RPC请求的AsyncResult,key对应包ID,范围为30bit,在timeout时间内,理论上不可能重复
     self.service = service
     self.close_callback = close_callback  # 断开毁掉
     Greenlet.__init__(self)
Example #20
0
 def __init__(self, ctx, manager, config, thrashers):
     Greenlet.__init__(self)
     self.ctx = ctx
     self.config = config
     self.e = None
     self.logger = log.getChild('daemon_watchdog')
     self.manager = manager
     self.name = 'watchdog'
     self.stopping = Event()
     self.thrashers = thrashers
 def __init__(self, stream_id , bit_rate_in_kbps = 128.0):
     Greenlet.__init__(self)
     self.stream_id = stream_id
     
     if(not AudioStreamReader.stream_buffers.get(self.stream_id, None)):
         buffer = Buffer()
         byte_rate = ((bit_rate_in_kbps/8)*1024)
         sleep_time = (buffer.chunk_byte_size*1.0)/byte_rate
         AudioStreamReader.stream_buffers[stream_id] = [buffer , byte_rate, sleep_time]
         
         
     self.buffer, self.byte_rate , self.sleep_time  = AudioStreamReader.stream_buffers[self.stream_id]
Example #22
0
    def __init__(self, context, node_name, address):
        Greenlet.__init__(self)

        self._log = logging.getLogger("DealerClient-%s" % (node_name, ))

        self._dealer_socket = context.socket(zmq.XREQ)
        self._dealer_socket.setsockopt(zmq.LINGER, 1000)
        self._log.debug("connecting to %s" % (address, ))
        self._dealer_socket.connect(address)

        self._send_queue = Queue(maxsize=None)
        self._delivery_queues = dict()
    def __init__(self, context, node_name, address):
        Greenlet.__init__(self)

        self._log = logging.getLogger("DealerClient-%s" % (node_name, ))

        self._dealer_socket = context.socket(zmq.XREQ)
        self._dealer_socket.setsockopt(zmq.LINGER, 1000)
        self._log.debug("connecting to %s" % (address, ))
        self._dealer_socket.connect(address)

        self._send_queue = Queue(maxsize=None)
        self._delivery_queues = dict()
Example #24
0
    def __init__(self, conf, input_queue, filtered_queue, db):
        LOGGER.info("Init Contract Proforma Filter.")
        Greenlet.__init__(self)
        self.config = conf
        self.cache_db = db
        self.input_queue = input_queue
        self.filtered_queue = filtered_queue

        self.resource = self.config['resource']
        self.resource_id = "{}_ID".format(self.resource[:-1]).upper()

        self.statusmap = self.config['filter_config'].get('statusmap', {})
        self.timeout = self.config['filter_config']['timeout']
Example #25
0
 def __init__(self, func, iterable, spawn=None):
     from gevent.queue import Queue
     Greenlet.__init__(self)
     if spawn is not None:
         self.spawn = spawn
     self.func = func
     self.iterable = iterable
     self.queue = Queue()
     self.count = 0
     self.waiting = []  # QQQ maybe deque will work faster there?
     self.index = 0
     self.maxindex = -1
     self.rawlink(self._on_finish)
 def __init__(self, func, iterable, spawn=None):
     from gevent.queue import Queue
     Greenlet.__init__(self)
     if spawn is not None:
         self.spawn = spawn
     self.func = func
     self.iterable = iterable
     self.queue = Queue()
     self.count = 0
     self.waiting = []  # QQQ maybe deque will work faster there?
     self.index = 0
     self.maxindex = -1
     self.rawlink(self._on_finish)
    def __init__(self, context, address, deliverator):
        Greenlet.__init__(self)

        self._log = logging.getLogger("PULLServer-%s" % (address, ))

        # we need a valid path for IPC sockets
        if address.startswith("ipc://"):
            prepare_ipc_path(address)

        self._pull_socket = context.socket(zmq.PULL)
        self._log.debug("binding")
        self._pull_socket.bind(address)

        self._deliverator = deliverator
Example #28
0
 def __init__(self, conf, input_queue, filtered_queue, db):
     logger.info("Init Close Framework Agreement Filter.")
     Greenlet.__init__(self)
     self.config = conf
     self.cache_db = db
     self.input_queue = input_queue
     self.filtered_queue = filtered_queue
     self.resource = self.config['resource']
     self.resource_id = "{}_ID".format(self.resource[:-1]).upper()
     self.procurement_method_types = tuple(
         self.config['filter_config']['procurementMethodTypes'])
     self.statuses = tuple(self.config['filter_config']['statuses'])
     self.lot_status = self.config['filter_config']['lot_status']
     self.timeout = self.config['filter_config']['timeout']
Example #29
0
 def __init__(self, conf, input_queue, filtered_queue, db):
     logger.info('Init Basic CouchDB Filter')
     Greenlet.__init__(self)
     self.config = conf
     self.input_queue = input_queue
     self.filtered_queue = filtered_queue
     self.db = db
     self.resource = self.config['resource']
     self.view_path = '_design/{}/_view/by_dateModified'.format(
         self.resource)
     self.bulk_query_interval = self.config['storage_config'][
         'bulk_query_interval']
     self.bulk_query_limit = self.config['storage_config'][
         'bulk_query_limit']
Example #30
0
    def __init__(self, context, address, deliverator):
        Greenlet.__init__(self)

        self._log = logging.getLogger("PULLServer-%s" % (address, ))

        # we need a valid path for IPC sockets
        if address.startswith("ipc://"):
            prepare_ipc_path(address)

        self._pull_socket = context.socket(zmq.PULL)
        self._log.debug("binding")
        self._pull_socket.bind(address)

        self._deliverator = deliverator
Example #31
0
 def __init__(self, conf, input_queue, filtered_queue, db):
     logger.info("Init Close Framework Agreement JMESPath Filter.")
     Greenlet.__init__(self)
     self.config = conf
     self.cache_db = db
     self.input_queue = input_queue
     self.filtered_queue = filtered_queue
     self.resource = self.config['resource']
     self.resource_id = "{}_ID".format(self.resource[:-1]).upper()
     self.filters = [
         jmespath.compile(expression['expression'])
         for expression in self.config['filter_config'].get('filters', [])
     ]
     self.timeout = self.config['filter_config']['timeout']
Example #32
0
 def __init__(self, desc, locals):
     Greenlet.__init__(self)
     self.locals = locals
     # mangle the socket
     self.desc = desc
     readline = desc.readline
     self.old = {}
     self.fixups = {
         'softspace': 0,
         'isatty': lambda: True,
         'flush': lambda: None,
         'readline': lambda *a: readline(*a).replace('\r\n', '\n'),
     }
     for key, value in self.fixups.iteritems():
         if hasattr(desc, key):
             self.old[key] = getattr(desc, key)
         setattr(desc, key, value)
Example #33
0
 def __init__(self, desc, locals):
     Greenlet.__init__(self)
     self.locals = locals
     # mangle the socket
     self.desc = desc
     readline = desc.readline
     self.old = {}
     self.fixups = {
         'softspace': 0,
         'isatty': lambda: True,
         'flush': lambda: None,
         'readline': lambda *a: readline(*a).replace('\r\n', '\n'),
     }
     for key, value in self.fixups.iteritems():
         if hasattr(desc, key):
             self.old[key] = getattr(desc, key)
         setattr(desc, key, value)
Example #34
0
    def __init__(self, ctx, config, cluster, daemons):
        Greenlet.__init__(self)

        self.ctx = ctx
        self.config = config
        self.cluster = cluster
        self.daemons = daemons

        self.e = None
        self.logger = log
        self.name = 'thrasher.rbd_mirror.[{cluster}]'.format(cluster = cluster)
        self.stopping = Event()

        self.randomize = bool(self.config.get('randomize', True))
        self.max_thrash = int(self.config.get('max_thrash', 1))
        self.max_thrash_delay = float(self.config.get('thrash_delay', 60.0))
        self.max_revive_delay = float(self.config.get('max_revive_delay', 10.0))
    def __init__(self, ctx, config, cluster, daemons):
        Greenlet.__init__(self)

        self.ctx = ctx
        self.config = config
        self.cluster = cluster
        self.daemons = daemons

        self.e = None
        self.logger = log
        self.name = 'thrasher.rbd_mirror.[{cluster}]'.format(cluster = cluster)
        self.stopping = Event()

        self.randomize = bool(self.config.get('randomize', True))
        self.max_thrash = int(self.config.get('max_thrash', 1))
        self.min_thrash_delay = float(self.config.get('min_thrash_delay', 60.0))
        self.max_thrash_delay = float(self.config.get('max_thrash_delay', 120.0))
        self.max_revive_delay = float(self.config.get('max_revive_delay', 10.0))
Example #36
0
    def __init__(self, ctx, manager, config, fs, max_mds):
        Greenlet.__init__(self)

        self.config = config
        self.ctx = ctx
        self.e = None
        self.logger = log.getChild('fs.[{f}]'.format(f = fs.name))
        self.fs = fs
        self.manager = manager
        self.max_mds = max_mds
        self.name = 'thrasher.fs.[{f}]'.format(f = fs.name)
        self.stopping = Event()

        self.randomize = bool(self.config.get('randomize', True))
        self.thrash_max_mds = float(self.config.get('thrash_max_mds', 0.0))
        self.max_thrash = int(self.config.get('max_thrash', 1))
        self.max_thrash_delay = float(self.config.get('thrash_delay', 120.0))
        self.thrash_in_replay = float(self.config.get('thrash_in_replay', False))
        assert self.thrash_in_replay >= 0.0 and self.thrash_in_replay <= 1.0, 'thrash_in_replay ({v}) must be between [0.0, 1.0]'.format(
            v=self.thrash_in_replay)
        self.max_replay_thrash_delay = float(self.config.get('max_replay_thrash_delay', 4.0))
        self.max_revive_delay = float(self.config.get('max_revive_delay', 10.0))
Example #37
0
    def __init__(
        self, 
        context, 
        server_node_name,
        server_address, 
        client_tag, 
        client_address,
        deliverator,
        connect_messages=list()
    ):
        Greenlet.__init__(self)

        self._log = logging.getLogger("ResilientClient-%s" % (
            server_address, 
        ))

        self._context = context
        self._server_node_name = server_node_name
        self._server_address = server_address

        self._client_tag = client_tag
        self._client_address = client_address
        self._deliverator = deliverator

        self._send_queue = gevent.queue.Queue()

        # prime the send queue with messages to be sent as soon
        # as we connect
        for connect_message in connect_messages:
            if not "message-id" in connect_message:
                connect_message["message-id"] = uuid.uuid1().hex
            message = message_format(
                ident=None, control=connect_message, body=None
            )
            self._send_queue.put(message)

        self._req_socket = None
        self.connected = False
Example #38
0
 def __init__(self, locals, conn):
     Greenlet.__init__(self)
     self.locals = locals
     self.desc = _fileobject(conn)
 def __init__(self, seconds):
     Greenlet.__init__(self)
     self.seconds = seconds
Example #40
0
 def __init__(self, run=None, restart=True, *args, **kwargs):
     self.run_target = run
     self.run_target_args = args
     self.run_target_kwargs = kwargs
     self.restart = restart
     Greenlet.__init__(self, run, *args, **kwargs)
Example #41
0
 def __init__(self, data_writer, message):
     Greenlet.__init__(self)
     self._resilient_client = data_writer._resilient_client
     self._message = message
Example #42
0
 def __init__(self, queue: Queue, processor: Processor, on_event):
     Greenlet.__init__(self)
     self.queue = queue
     self.processor = processor
     self.on_event = on_event
Example #43
0
 def __init__(self, locals, conn, banner=None):
     Greenlet.__init__(self)
     self.locals = locals
     self.desc = _fileobject(conn)
     self.banner = banner
 def __init__(self, test_number, delay_interval):
     Greenlet.__init__(self)
     self._test_number = test_number
     self._delay_interval = delay_interval
Example #45
0
 def __init__(self, locals, conn, banner=None):
     Greenlet.__init__(self)
     self.locals = locals
     self.desc = _fileobject(conn)
     self.banner = banner
 def __init__(self, delay_interval):
     Greenlet.__init__(self)
     self._delay_interval = delay_interval
 def __init__(self, halt_event, user_identity, test_script):
     Greenlet.__init__(self)
     BaseCustomer.__init__(self, halt_event, user_identity, test_script)
 def __init__(self, connection_pool, test_number, delay_interval):
     Greenlet.__init__(self)
     self._connection_pool = connection_pool
     self._test_number = test_number
     self._delay_interval = delay_interval
 def __init__(self, imsi, apid, aid):
     # super(greenlet, self).__init__()
     Greenlet.__init__(self)
     self.imsi = imsi
     self.apid = apid
     self.aid = aid
 def __init__(self, mobile, apid, aid):
     # super(greenlet, self).__init__()
     Greenlet.__init__(self)
     self.mobile = mobile
     self.apid = apid
     self.aid = aid
Example #51
0
 def __init__(self, locals, conn, banner=None):
     Greenlet.__init__(self)
     self.locals = locals
     self.desc = _SocketIO(conn)
     self.banner = banner
 def __init__(self, halt_event, user_identity, test_script):
     Greenlet.__init__(self)
     BaseCustomer.__init__(self, halt_event, user_identity, test_script)
Example #53
0
 def __init__(self, locals, conn, banner=None):
     Greenlet.__init__(self)
     self.locals = locals
     self.desc = _fileobject(conn, mode='rw', close=True)
     self.banner = banner
Example #54
0
 def __init__(self, current):
     # super(greenlet, self).__init__()
     Greenlet.__init__(self)
     self.current = current
 def __init__(self, connection_pool, delay_interval):
     Greenlet.__init__(self)
     self._connection_pool = connection_pool
     self._delay_interval = delay_interval
 def __init__(self, info):
     # super(greenlet, self).__init__()
     Greenlet.__init__(self)
     self.info = info