jim-easterbrook / python-gphoto2

Python interface to libgphoto2
GNU Lesser General Public License v3.0
360 stars 59 forks source link

Cancel operation #86

Closed TermanEmil closed 4 years ago

TermanEmil commented 5 years ago

I would like to have the possibility to cancel some of the operations from a different thread.

I think that gp_context_cancel() (from libgphoto2) should do the job. But I've noticed that you ignore this function: %ignore gp_context_cancel;.

I couldn't find an example.

What I'm trying to do: I have a Django application that controls the cameras. Sometimes, the access to the camera is blocked and some operations, like .exit() are taking forever. How do I cancel the operations on the cameras?

jim-easterbrook commented 5 years ago

As I understand it, gp_context_cancel can be called by a camera driver to ask the user if they'd like to cancel the operation. It is unlikely anyone would write a camera driver in Python so I've ignored the function.

You should be able to use gp_context_set_cancel_func to give libgphoto2 a Python function to call if the camera driver calls gp_context_cancel.

jim-easterbrook commented 5 years ago

I should add that the Canon cameras I use don't seem to call any of these functions in my limited testing. The libgphoto2 documentation is not very clear, but I think I've understood it correctly. http://www.gphoto.org/doc/api/gphoto2-context_8h.html#a1decda483ec848e9cfd0ce68fb35ba82

TermanEmil commented 5 years ago

Sorry, I didn't quite get it. How exactly do I cancel something?

jim-easterbrook commented 5 years ago

I may not have got it either. I don't know of any way to cancel an operation if the camera driver is busy doing something. (It might be hard to do without leaving the USB in a messed up state. I've had to reset cameras when things have gone wrong.)

Could I suggest asking on one of the gphoto2 mailing lists, with more specific information about what it is you need to cancel and what sort of camera you're using.

TermanEmil commented 5 years ago

I'm using Nikon Z6. Sometimes, the camera gets into a blocked state (especially after I do something unexpected, like killing the program). So, I would like to cancel any operation if it takes too much time. For example, when I use the .exit() method when the camera is blocked, I have to wait for like 10 seconds until it raises an error. I would like to allow my user to cancel this operation. The same thing applies to taking pictures. I would like to give my user the ability to cancel a capture.

Do you think there's any way I could achieve this without touching the camera or the cables?

jim-easterbrook commented 5 years ago

I don't know of any way round this, but I'm not any sort of expert in using libgphoto2.