示例#1
0
def test_heappop():
    n = 1000
    a = [randrange(1000) for _ in range(n)]
    heapify(a)
    previous = heappop(a)
    pop_count = 1
    while a:
        assert previous <= (previous := heappop(a))
        pop_count += 1
    assert pop_count == n
    assert len(a) == 0
示例#2
0
 def unplan_call(self, h):
     # remove a call from the queue
     q = self.q
     rv = 0
     for i in range(len(q)):
         try:
             if q[i][1] is h:
                 q[i] = (0, 0)
         except IndexError:
             break
     heapq.heapify(q)
     while q and q[0] == (0, 0):
         heapq.heappop(q)
         rv += 1
     return rv
示例#3
0
    def connect(self, device_id):

        self.handle = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sockaddr = socket.getaddrinfo(CONFIG_SERVER_IP,
                                      CONFIG_SERVER_PORT)[0][-1]

        # connect to server
        try:
            self.handle.connect(sockaddr)
        except:
            self.handle.close()
            self.handle = None
            return False

        # Set device info
        buf = bytes()
        buf += struct.pack('I', device_id)
        sendCap = self.avs_set_capabilities(CONF_AUDIO_SEND_FORMAT,
                                            CONF_AUDIO_SEND_BITDEPTH,
                                            CONF_AUDIO_SEND_BITRATE,
                                            CONF_AUDIO_SEND_CHANNEL)
        buf += struct.pack('H', sendCap)
        recvCap = self.avs_set_capabilities(CONF_AUDIO_RECV_FORMAT,
                                            CONF_AUDIO_RECV_BITDEPTH,
                                            CONF_AUDIO_RECV_BITRATE,
                                            CONF_AUDIO_RECV_CHANNEL)
        buf += struct.pack('H', recvCap)

        # Send device info
        self.handle.sendall(buf)

        # Initialize variables
        self.queue_data = []
        heapq.heapify(self.queue_data)
        self.buffer_send = bytearray(CONFIG_BUFFER_SEND_SIZE)
        return True
示例#4
0
文件: my_app.py 项目: xyicheng/LabWeb
from sht30 import SHT30
from ds3231_time import cl_id
import gc
alloc_emergency_exception_buf(100)
sensor_k = MAX6675()
sensor3 = SHT30()
button = Pin(0, Pin.IN)
SERVER = "192.168.100.101"
CLIENT_ID = cl_id()
TOPIC = b"esp001log"
DATA_TP = b"data_" + CLIENT_ID
sub_flag = 100
i_pum = 0
i_snd = 0
i_data = []
uheapq.heapify(i_data)


class Foo():
    def __init__(self):
        self.push_ref = self.push
        p2 = Pin(2, Pin.IN)
        p2.irq(trigger=Pin.IRQ_RISING, handler=self.cb)

    def push(self, _):
        global i_pum, i_snd, i_data, sub_flag
        if -35 < (i_pum - i_snd) < 61:
            try:
                kT = sensor_k.measure()
                kTr = '%f' % (kT)
                if kTr == 'nan':
示例#5
0
    print("IndexError")

try:
    heapq.heappush((), 1)
except TypeError:
    print("TypeError")


def pop_and_print(h):
    l = []
    while h:
        l.append(str(heapq.heappop(h)))
    print(' '.join(l))


h = []
heapq.heappush(h, 3)
heapq.heappush(h, 1)
heapq.heappush(h, 2)
print(h)
pop_and_print(h)

h = [4, 3, 8, 9, 10, 2, 7, 11, 5]
heapq.heapify(h)
print(h)
heapq.heappush(h, 1)
heapq.heappush(h, 6)
heapq.heappush(h, 12)
print(h)
pop_and_print(h)
示例#6
0
    heapq.heappop([])
except IndexError:
    print("IndexError")

try:
    heapq.heappush((), 1)
except TypeError:
    print("TypeError")

def pop_and_print(h):
    l = []
    while h:
        l.append(str(heapq.heappop(h)))
    print(' '.join(l))

h = []
heapq.heappush(h, 3)
heapq.heappush(h, 1)
heapq.heappush(h, 2)
print(h)
pop_and_print(h)

h = [4, 3, 8, 9, 10, 2, 7, 11, 5]
heapq.heapify(h)
print(h)
heapq.heappush(h, 1)
heapq.heappush(h, 6)
heapq.heappush(h, 12)
print(h)
pop_and_print(h)
示例#7
0
def test_heapify():
    n = 1000
    a = [randrange(1000) for _ in range(n)]
    heapify(a)
    assert_heap_ordered(a)