jim-easterbrook / python-gphoto2

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

How is gp_camera_wait_for_event working ? #27

Closed benoitguigal closed 7 years ago

benoitguigal commented 7 years ago

I want to wait for a GP_EVENT_FILE_ADDED event. Here is my code:

gp.check_result(gp.gp_camera_wait_for_event(camera, gp.GP_EVENT_FILE_ADDED, context))

I would expect the function to wait until the event happen but instead it returns immediately (0, None) My workaround is to create a while loop like this:

while True:
    event_type, data = gp.check_result(gp.gp_camera_wait_for_event(camera, gp.GP_EVENT_FILE_ADDED, context))
    if event_type == gp.GP_EVENT_FILE_ADDED:
        camera_file_path = data
        return camera_file_path
    time.sleep(0.1)

which is working but does not feel right. Any help would be greatly appreciated.

jim-easterbrook commented 7 years ago

I've not used gp_camera_wait_for_event myself so I don't know what to expect. It's probably camera and/or driver dependent. This is a question about libgphoto2 rather than about the Python interface so it might be worth asking on the gphoto2 mailing list.

jim-easterbrook commented 7 years ago

I've just looked at the documentation of gp_camera_wait_for_event. The second parameter is a timeout value, but you are passing gp.GP_EVENT_FILE_ADDED so your call is timing out in 2 milliseconds.

benoitguigal commented 7 years ago

In gphoto2 version >= 2.5.6 it is possible to pass string value like 'FILEADDED' or 'CAPTURECOMPLETE' to the wait_event function. https://github.com/gphoto/gphoto2/blob/master/NEWS. Do you think it is possible to call this underlying function instead of the function with the timeout ?

jim-easterbrook commented 7 years ago

python-gphoto2 is a Python interface to the libgphoto2 C library (see http://www.gphoto.org/doc/api/). It doesn't add functionality unless absolutely necessary, e.g. to use Python types. The gphoto2 command line tool is a separate entity. Its wait-event option presumably uses gp_camera_wait_for_event internally.

You can easily write your own Python function to call gp_camera_wait_for_event repeatedly until it returns the event type you want.

benoitguigal commented 7 years ago

ok it very clear, thanks a lot