當前位置: 首頁>>代碼示例>>Python>>正文


Python circular_buffer.CircularBuffer類代碼示例

本文整理匯總了Python中circular_buffer.CircularBuffer的典型用法代碼示例。如果您正苦於以下問題:Python CircularBuffer類的具體用法?Python CircularBuffer怎麽用?Python CircularBuffer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了CircularBuffer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Peer

class Peer(object):
    def __init__(self, peer_id, socket):
        self.peer_id = peer_id
        self.socket = socket
        self.pending_requests = {}  # req_id -> ValueEvent
        self.incoming_buffer = msgpack.Unpacker()
        self.outgoing_buffer = CircularBuffer(OUTGOING_PEER_BUFFER_SIZE)
        self.lock = threading.Lock()

    def close(self):
        try:
            self.lock.release()
        except threading.ThreadError:
            pass  # lock may not have been acquired.
        self.socket.close()

    def add_request(self, req_id, request_bytes, value_event):
        """Add ValueEvent to pending requests and write request_bytes to
        outgoing_buffer"""
        with self.lock:
            self.pending_requests[req_id] = value_event
            self.outgoing_buffer.write(request_bytes)

    def handle_response(self, response):
        """Extract req_id from response and check if there is a pending request 
        for the req_id. If so set the value.
        """
        with self.lock:
            req_id, status, message = response
            if req_id in self.pending_requests:  # request may have timed out
                self.pending_requests[req_id].set((status, message))

    def remove_request(self, req_id):
        with self.lock:
            del self.pending_requests[req_id]
開發者ID:chartbeat-labs,項目名稱:wade,代碼行數:35,代碼來源:chorus.py

示例2: test_read_back_oldest_item

 def test_read_back_oldest_item(self):
     buf = CircularBuffer(3)
     buf.write('1')
     buf.write('2')
     buf.read()
     buf.write('3')
     buf.read()
     self.assertEqual('3', buf.read())
開發者ID:ozan,項目名稱:solutions,代碼行數:8,代碼來源:circular_buffer_test.py

示例3: __init__

 def __init__(self, peer_id, socket):
     self.peer_id = peer_id
     self.socket = socket
     self.pending_requests = {}  # req_id -> ValueEvent
     self.incoming_buffer = msgpack.Unpacker()
     self.outgoing_buffer = CircularBuffer(OUTGOING_PEER_BUFFER_SIZE)
     self.lock = threading.Lock()
開發者ID:chartbeat-labs,項目名稱:wade,代碼行數:7,代碼來源:chorus.py

示例4: test_overwrite_full_buffer

 def test_overwrite_full_buffer(self):
     buf = CircularBuffer(2)
     buf.write('1')
     buf.write('2')
     buf.overwrite('A')
     self.assertEqual('2', buf.read())
     self.assertEqual('A', buf.read())
     with self.assertRaises(BufferEmptyException):
         buf.read()
開發者ID:ozan,項目名稱:solutions,代碼行數:9,代碼來源:circular_buffer_test.py

示例5: test_overwrite_replaces_oldest_item

 def test_overwrite_replaces_oldest_item(self):
     buf = CircularBuffer(2)
     buf.write('1')
     buf.write('2')
     buf.overwrite('3')
     self.assertEqual(buf.read(), '2')
     self.assertEqual(buf.read(), '3')
開發者ID:ThomasZumsteg,項目名稱:exercism-python,代碼行數:7,代碼來源:circular_buffer_test.py

示例6: test_write_and_read_back_multiple_items

 def test_write_and_read_back_multiple_items(self):
     buf = CircularBuffer(2)
     buf.write('1')
     buf.write('2')
     self.assertEqual('1', buf.read())
     self.assertEqual('2', buf.read())
     with self.assertRaises(BufferEmptyException):
         buf.read()
開發者ID:ozan,項目名稱:solutions,代碼行數:8,代碼來源:circular_buffer_test.py

示例7: test_write_full_buffer

 def test_write_full_buffer(self):
     buf = CircularBuffer(2)
     buf.write('1')
     buf.write('2')
     with self.assertRaises(BufferFullException):
         buf.write('A')
開發者ID:ozan,項目名稱:solutions,代碼行數:6,代碼來源:circular_buffer_test.py

示例8: test_read_just_written_item

 def test_read_just_written_item(self):
     buf = CircularBuffer(1)
     buf.write('1')
     self.assertEqual(buf.read(), '1')
開發者ID:ThomasZumsteg,項目名稱:exercism-python,代碼行數:4,代碼來源:circular_buffer_test.py

示例9: test_alternate_write_and_read

 def test_alternate_write_and_read(self):
     buf = CircularBuffer(2)
     buf.write('1')
     self.assertEqual('1', buf.read())
     buf.write('2')
     self.assertEqual('2', buf.read())
開發者ID:ozan,項目名稱:solutions,代碼行數:6,代碼來源:circular_buffer_test.py

示例10: test_clearing_buffer

 def test_clearing_buffer(self):
     buf = CircularBuffer(3)
     for c in '123':
         buf.write(c)
     buf.clear()
     with self.assertRaises(BufferEmptyException):
         buf.read()
     buf.write('1')
     buf.write('2')
     self.assertEqual('1', buf.read())
     buf.write('3')
     self.assertEqual('2', buf.read())
開發者ID:ozan,項目名稱:solutions,代碼行數:12,代碼來源:circular_buffer_test.py

示例11: range

    is_init = False
    niveau_count = 0
    platau_count = 0

    print "signal walking"
    for i in range(1, buffer.size-1):

        ksum = 0
        for k in range(-1,2):
            w = -k
            ksum += buffer.value(i+k) * w

        print ksum
        if is_init:
            diff = ksum - last_ksum

        last_ksum = ksum
        is_init = True


size = 10
data = [0 for i in range(size)]
buffer = CircularBuffer(data, size)

for i in range(25):
    #buffer.add((i-5)**2.0)
    buffer.add(i)
    peak_detect(buffer)


開發者ID:stefanbesler,項目名稱:testing,代碼行數:28,代碼來源:peeker.py

示例12: test_write_and_read_back_one_item

 def test_write_and_read_back_one_item(self):
     buf = CircularBuffer(1)
     buf.write('1')
     self.assertEqual('1', buf.read())
     with self.assertRaises(BufferEmptyException):
         buf.read()
開發者ID:ozan,項目名稱:solutions,代碼行數:6,代碼來源:circular_buffer_test.py

示例13: test_read_empty_buffer

 def test_read_empty_buffer(self):
     buf = CircularBuffer(1)
     with self.assertRaises(BufferEmptyException):
         buf.read()
開發者ID:ozan,項目名稱:solutions,代碼行數:4,代碼來源:circular_buffer_test.py

示例14: test_write_and_read_back_multiple_items_ordered

 def test_write_and_read_back_multiple_items_ordered(self):
     buf = CircularBuffer(2)
     buf.write('1')
     buf.write('2')
     self.assertEqual(buf.read(), '1')
     self.assertEqual(buf.read(), '2')
開發者ID:ThomasZumsteg,項目名稱:exercism-python,代碼行數:6,代碼來源:circular_buffer_test.py

示例15: test_overwrite_non_full_buffer

 def test_overwrite_non_full_buffer(self):
     buf = CircularBuffer(2)
     buf.write('1')
     buf.overwrite('2')
     self.assertEqual(buf.read(), '1')
     self.assertEqual(buf.read(), '2')
開發者ID:ThomasZumsteg,項目名稱:exercism-python,代碼行數:6,代碼來源:circular_buffer_test.py


注:本文中的circular_buffer.CircularBuffer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。