Reading from a blocking queue in async def with fork
See original GitHub issueI’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:
- Created 3 years ago
- Comments:23 (23 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub 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.
@raysalemi FWIW, we also have a chat room at https://gitter.im/cocotb/Lobby where this might be easier and quicker to discuss.