当前位置: 首页>>代码示例>>Python>>正文


Python CircularBuffer.write方法代码示例

本文整理汇总了Python中circular_buffer.CircularBuffer.write方法的典型用法代码示例。如果您正苦于以下问题:Python CircularBuffer.write方法的具体用法?Python CircularBuffer.write怎么用?Python CircularBuffer.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在circular_buffer.CircularBuffer的用法示例。


在下文中一共展示了CircularBuffer.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_overwrite_replaces_oldest_item

# 需要导入模块: from circular_buffer import CircularBuffer [as 别名]
# 或者: from circular_buffer.CircularBuffer import write [as 别名]
 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,代码行数:9,代码来源:circular_buffer_test.py

示例2: Peer

# 需要导入模块: from circular_buffer import CircularBuffer [as 别名]
# 或者: from circular_buffer.CircularBuffer import write [as 别名]
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,代码行数:37,代码来源:chorus.py

示例3: test_write_and_read_back_multiple_items

# 需要导入模块: from circular_buffer import CircularBuffer [as 别名]
# 或者: from circular_buffer.CircularBuffer import write [as 别名]
 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,代码行数:10,代码来源:circular_buffer_test.py

示例4: test_read_back_oldest_item

# 需要导入模块: from circular_buffer import CircularBuffer [as 别名]
# 或者: from circular_buffer.CircularBuffer import write [as 别名]
 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,代码行数:10,代码来源:circular_buffer_test.py

示例5: test_overwrite_full_buffer

# 需要导入模块: from circular_buffer import CircularBuffer [as 别名]
# 或者: from circular_buffer.CircularBuffer import write [as 别名]
 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,代码行数:11,代码来源:circular_buffer_test.py

示例6: test_overwrite_replaces_oldest_remaining_item

# 需要导入模块: from circular_buffer import CircularBuffer [as 别名]
# 或者: from circular_buffer.CircularBuffer import write [as 别名]
 def test_overwrite_replaces_oldest_remaining_item(self):
     buf = CircularBuffer(3)
     buf.write('1')
     buf.write('2')
     buf.write('3')
     self.assertEqual(buf.read(), '1')
     buf.write('4')
     buf.overwrite('5')
     self.assertEqual(buf.read(), '3')
     self.assertEqual(buf.read(), '4')
     self.assertEqual(buf.read(), '5')
开发者ID:ThomasZumsteg,项目名称:exercism-python,代码行数:13,代码来源:circular_buffer_test.py

示例7: test_clearing_buffer

# 需要导入模块: from circular_buffer import CircularBuffer [as 别名]
# 或者: from circular_buffer.CircularBuffer import write [as 别名]
 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,代码行数:14,代码来源:circular_buffer_test.py

示例8: test_alternate_read_and_overwrite

# 需要导入模块: from circular_buffer import CircularBuffer [as 别名]
# 或者: from circular_buffer.CircularBuffer import write [as 别名]
 def test_alternate_read_and_overwrite(self):
     buf = CircularBuffer(5)
     for c in '123':
         buf.write(c)
     buf.read()
     buf.read()
     buf.write('4')
     buf.read()
     for c in '5678':
         buf.write(c)
     buf.overwrite('A')
     buf.overwrite('B')
     self.assertEqual('6', buf.read())
     self.assertEqual('7', buf.read())
     self.assertEqual('8', buf.read())
     self.assertEqual('A', buf.read())
     self.assertEqual('B', buf.read())
     with self.assertRaises(BufferEmptyException):
         buf.read()
开发者ID:ozan,项目名称:solutions,代码行数:21,代码来源:circular_buffer_test.py

示例9: test_write_and_read_back_multiple_items_ordered

# 需要导入模块: from circular_buffer import CircularBuffer [as 别名]
# 或者: from circular_buffer.CircularBuffer import write [as 别名]
 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,代码行数:8,代码来源:circular_buffer_test.py

示例10: test_write_full_buffer

# 需要导入模块: from circular_buffer import CircularBuffer [as 别名]
# 或者: from circular_buffer.CircularBuffer import write [as 别名]
 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,代码行数:8,代码来源:circular_buffer_test.py

示例11: test_cant_write_to_full_buffer

# 需要导入模块: from circular_buffer import CircularBuffer [as 别名]
# 或者: from circular_buffer.CircularBuffer import write [as 别名]
 def test_cant_write_to_full_buffer(self):
     buf = CircularBuffer(1)
     buf.write('1')
     with self.assertRaisesWithMessage(BufferFullException):
         buf.write('2')
开发者ID:ThomasZumsteg,项目名称:exercism-python,代码行数:7,代码来源:circular_buffer_test.py

示例12: test_alternate_write_and_read

# 需要导入模块: from circular_buffer import CircularBuffer [as 别名]
# 或者: from circular_buffer.CircularBuffer import write [as 别名]
 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,代码行数:8,代码来源:circular_buffer_test.py

示例13: test_clearing_buffer

# 需要导入模块: from circular_buffer import CircularBuffer [as 别名]
# 或者: from circular_buffer.CircularBuffer import write [as 别名]
 def test_clearing_buffer(self):
     buf = CircularBuffer(1)
     buf.write('1')
     buf.clear()
     with self.assertRaisesWithMessage(BufferEmptyException):
         buf.read()
开发者ID:ThomasZumsteg,项目名称:exercism-python,代码行数:8,代码来源:circular_buffer_test.py

示例14: test_write_and_read_back_one_item

# 需要导入模块: from circular_buffer import CircularBuffer [as 别名]
# 或者: from circular_buffer.CircularBuffer import write [as 别名]
 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,代码行数:8,代码来源:circular_buffer_test.py

示例15: test_read_just_written_item

# 需要导入模块: from circular_buffer import CircularBuffer [as 别名]
# 或者: from circular_buffer.CircularBuffer import write [as 别名]
 def test_read_just_written_item(self):
     buf = CircularBuffer(1)
     buf.write('1')
     self.assertEqual(buf.read(), '1')
开发者ID:ThomasZumsteg,项目名称:exercism-python,代码行数:6,代码来源:circular_buffer_test.py


注:本文中的circular_buffer.CircularBuffer.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。