High load when trying to fetch image
voegtlel opened this issue · comments
Describe the bug
When trying to fetch an image, the fetch_buffer
method runs in an infinite loop without threaded sleeps.
Expected behavior
The method fetch_buffer should use proper events to synchronize with the acquisition thread. Or rather use a queue.Queue
for fetching ready buffers.
Desktop (please complete the following information):
- OS: N/A
- Python: 3.6 (doesn't matter)
- Harvester: 1.0.3
- GenTL Producer: N/A
- Camera: N/A
Additional context
Related source code lines:
https://github.com/genicam/harvesters/blob/master/src/harvesters/core.py#L2074 (this is where the cpu-hungry loop starts)
https://github.com/genicam/harvesters/blob/master/src/harvesters/core.py#L1976 (this is where the synchronization must happen)
https://github.com/genicam/harvesters/blob/master/src/harvesters/core.py#L1574 (maybe use queue.Queue
here)
@voegtlel Hi, thank you for your valuable feedback. Okay, I will review the design and try to improve it. /Kazunari
JFYI: Working on it. It seems to be promising. I will let you know once it turns ready. :-)
@voegtlel Hi. I have just committed a changeset that resolves this issue to the following branch:
https://github.com/genicam/harvesters/tree/_issue_120
Could you try that out when you can, please? I need your feedback to judge if I should merge this or not. You can manually install Harvester with the following command in the working copy:
$ git clone https://github.com/genicam/harvesters.git && cd harvesters && git checkout origin/_issue_120 && python setup.py install
Note that perhaps you should uninstall Harvester in advance if you have already installed it:
$ pip uninstall harvesters
Thanks,
Kazunari
@voegtlel Please note that I would not be able to merge the branch without your confirmation. ;-)
Oh I'm sorry, I was on vacation, and now I'm in quarantine, so I don't have the hardware to verify your changes :(
I checked your commits though, and they basically look fine. I only see one issue: If you specify a very long waiting time for fetch_buffer
, you cannot exit that method. I usually solve this by enqueuing None
as a special "exit" value. But I guess looping with a small timeout should also work fine.