cocotb: Reading from a blocking queue in async def with fork

I’m trying to create an asynchronous driver that will read transactions from a Queue. I’ve got this coroutine:

async def bfm_send_op(dut):
    while True:
        (A, B, op) = AluDriverBfm.queue.get()
        dut.A = A
        dut.B = B
        dut.op =op.value
        dut.start = 1
        await RisingEdge(dut.done)
        await FallingEdge(dut.clk)
        dut.start = 0

And I launch it like this:

@cocotb.test()
async def test_alu(dut):
    AluDriverBfm(dut, "ALUDRIVERBFM")
    print("FORKING THINGS!")
    cocotb.fork(bfm_send_op(dut))
    cocotb.fork(Clock(dut.clk, 100).start())
    print("DONE FORKING THINGS!")

But I see this:

     0.00ns INFO     cocotb.regression                         regression.py:459  in _start_test                     Running test 1/1: test_alu
     0.00ns INFO     cocotb.test.test_alu.0x7fd592f0e4c0       decorators.py:255  in _advance                        Starting test: "test_alu"
                                                                                                                     Description: None
FORKING THINGS!

Investigation shows that the fork call is not returning because the routine blocks at the get. I thought that fork would run my loop independently as it does with Clock().start()

What am I doing wrong? Why does fork not just leave the coroutine waiting on the get and move on to the next thing?

Thanks! Ray

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 23 (23 by maintainers)

Most upvoted comments

FWIW, gitter is kinda terrible. Threading (heh) is not working correctly on my phone app at the moment. And it keeps refusing to mark messages as read.