示例#1
0
def sop(matA, matB, row, col):
    tutil.tlog("A={} B={}".format(row, col))
    assert matA.shape[1] == matB.shape[
        0], "Matrix cannot be multiplied. A={}, B={}".format(
            matA.shape, matB.shape)
    # Sleep for a small random interval to see the threads in play
    tutil.sleepMilli(np.random.randint(10))
    return np.sum(matA[row, :] * matB[:, col])
示例#2
0
def producer(q, milli=None):
    for i in range(10):
        mesg = "Item #{:03d}".format(i + 1)
        q.put(mesg)
        tutil.tlog(mesg)
        tutil.sleepMilli(milli)
示例#3
0
def main():
    q = Queue(maxsize=3)
    tutil.tlog("Main started")
    threading.Thread(target=producer, name="tMaker", args=[q, 100]).start()
    threading.Thread(target=consumer, name="tTaker", args=[q, 300]).start()
    tutil.tlog("Main exited")
示例#4
0
def consumer(q, milli=None):
    for i in range(10):
        mesg = q.get()
        tutil.tlog(mesg)
        tutil.sleepMilli(milli)
示例#5
0
def do_something(zz, mesg=None):
    mesg = "" if mesg is None else " Mesg=" + mesg
    tutil.tlog("Sleeping for {} milli.{}".format(zz, mesg))
    tutil.sleepMilli(zz)
    tutil.tlog("Done sleeping")