alliedvision / VmbPy

Python API of the Vimba X SDK
BSD 2-Clause "Simplified" License
23 stars 8 forks source link

Using vmbpy.VmbSystem.get_instance() outside of a context manager #23

Open Th-Havy opened 8 months ago

Th-Havy commented 8 months ago

Hello,

Because of the current software architecture of my program I cannot use the vmb/camera using a context manager. I would like to just initialize the communication and the camera at startup, and keep a reference to it during the whole lifetime of the program.

I tried calling manually __enter__() and __exit__(), which works to some extend. The issue is that I get a huge amount of trace logs in the console, which I cannot remove despite my attempts using vmb.enable_log().

I know that calling manually enter and exit is not an optimal solution but it seems to be the only workaround to use a camera outside of a with statement.

My question is thus the following: is there a proper way to use vimba x outside of a context manager. If not, is there at least a way to disable all the trace logs that are written to the console when manually calling enter/exit.

Thanks

GuillaumeBeaudin commented 8 months ago

Hello @Th-Havy !

I had a similar issue with the context manager. On my side, I tried to start it before starting a GUI, but when I was trying to access the cam object from another thread it would fail saying that I was outside the context manager. While I would also prefer to be able to access the camera outside the context manager, I implemented a solutions that work quite well. Basically, I used the context manager to connect to the camera in another thread (it could probably be in another process also) and I implemented a queue system to send command and receive data. You can see an exemple of what I'm talking about here:

https://github.com/alliedvision/VmbPy/issues/22#issuecomment-1912304112

I hope it can be useful for you!

Cheers,

Guillaume