question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reading from a blocking queue in async def with fork

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:23 (23 by maintainers)

github_iconTop GitHub Comments

1reaction
alexforencichcommented, Dec 3, 2020

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.

0reactions
cmarqucommented, Dec 3, 2020

@raysalemi FWIW, we also have a chat room at https://gitter.im/cocotb/Lobby where this might be easier and quicker to discuss.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ForkjoinPool doesnt have a BlockingQueue - Stack Overflow
I have been using ThreadPoolExecutor and blocking queues for both the above purposes are able to help asynchronous operations, which seems ...
Read more >
day-1-ZIO-mastering-async-and-concurrent-programming
Implement a function to read a file on the blocking thread pool, storing. * the result into a string. */. def readFile(file: String):...
Read more >
BlockingQueue (Java Platform SE 8 ) - Oracle Help Center
Returns the number of additional elements that this queue can ideally (in the absence of memory or resource constraints) accept without blocking, or...
Read more >
Guide to the Fork/Join Framework in Java - Baeldung
An intro to the fork/join framework presented in Java 7 and the tools to help speed up parallel processing by attempting to use...
Read more >
Speeding Up Python with Concurrency, Parallelism, and asyncio
Whether you're dealing with external web resources, reading from and writing to ... What does it mean when something is non-blocking?
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found