After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 762496 - Use a more idiomatic GIO-like API
Use a more idiomatic GIO-like API
Status: RESOLVED OBSOLETE
Product: grilo
Classification: Other
Component: core
unspecified
Other All
: Normal enhancement
: ---
Assigned To: grilo-maint
grilo-maint
Depends on:
Blocks:
 
 
Reported: 2016-02-22 22:00 UTC by Debarshi Ray
Modified: 2018-09-24 09:41 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Debarshi Ray 2016-02-22 22:00:02 UTC
It would be nice if Grilo's asynchronous functions had a idiomatic GIO-like pattern with GCancellables, GAsyncReadyCallbacks, etc..

More importantly, the synchronous functions are not usable from inside a threaded path because they get stuck and never return. As far as I can tell, this is due to not using a thread default GMainContext. Again, something that is typical in GIO-land, when a synchronous method is implemented in terms of its asynchronous counterpart.

It can be worked around by using the async variant and wrapping it around a thread default GMainContext and running a GMainLoop.
Comment 1 Bastien Nocera 2016-02-23 12:10:44 UTC
(In reply to Debarshi Ray from comment #0)
> It would be nice if Grilo's asynchronous functions had a idiomatic GIO-like
> pattern with GCancellables, GAsyncReadyCallbacks, etc..
> 
> More importantly, the synchronous functions are not usable from inside a
> threaded path because they get stuck and never return. As far as I can tell,
> this is due to not using a thread default GMainContext. Again, something
> that is typical in GIO-land, when a synchronous method is implemented in
> terms of its asynchronous counterpart.

This is a plain bug, test case would be useful. I'm guessing it's a problem with the async machinery that doesn't check for whether the dispatch is done from the right thread.

Please file a separate bug with a test case and we can look into it.

> It can be worked around by using the async variant and wrapping it around a
> thread default GMainContext and running a GMainLoop.

The reason it's done that way is because we want to batch results, otherwise you hog the main loop preparing results, and dispatching them one-by-one.

GIO-like API should be possible rather easily for functions that only return a single result, but the API changes for the browse and search functions would be pretty big, with the problems mentioned above.
Comment 2 Juan A. Suarez Romero 2016-03-04 10:37:38 UTC
(In reply to Bastien Nocera from comment #1)
 
> The reason it's done that way is because we want to batch results, otherwise
> you hog the main loop preparing results, and dispatching them one-by-one.
>

Couldn't the source do it in a separate task and then use notify results are ready to be dispatched, and use  GIO-alike API to get them?
Comment 3 Bastien Nocera 2016-03-04 12:56:13 UTC
(In reply to Juan A. Suarez Romero from comment #2)
> (In reply to Bastien Nocera from comment #1)
>  
> > The reason it's done that way is because we want to batch results, otherwise
> > you hog the main loop preparing results, and dispatching them one-by-one.
> >
> 
> Couldn't the source do it in a separate task and then use notify results are
> ready to be dispatched, and use  GIO-alike API to get them?

Sure it could, but we'd need to know what the new API would look like before committing to writing any code.
Comment 4 Debarshi Ray 2017-02-17 09:08:31 UTC
(In reply to Bastien Nocera from comment #3)
> (In reply to Juan A. Suarez Romero from comment #2)
> > (In reply to Bastien Nocera from comment #1)
> >  
> > > The reason it's done that way is because we want to batch results, otherwise
> > > you hog the main loop preparing results, and dispatching them one-by-one.
> > >
> > 
> > Couldn't the source do it in a separate task and then use notify results are
> > ready to be dispatched, and use  GIO-alike API to get them?
> 
> Sure it could, but we'd need to know what the new API would look like before
> committing to writing any code.

There is prior art in the GNOME platform for this (as I might have mentioned a few times elsewhere, but I might misremember).

There is g_file_copy and g_file_copy_async/finish [1]. It uses the 'progress_callback' to notify the caller as chunks of bytes are copied from source to destination.

Then there is libgdata, which is a bit more elaborate. For example, to get all the entries from your Google Drive, you'd first create a batched GDataDocumentsQuery with gdata_documents_query_new_with_limits [2]. This acts, sort of, like a cursor. Then, you'd use gdata_documents_service_query_documents [3] to get a batched GDataDocumentsFeed. Once you are done reading this feed, gdata_query_next_page [4] will move your existing GDataDocumentsQuery instance to the next page. Repeat the steps to get your next batch. This is what gvfs and gnome-online-miners use to access Drive content.

[1] https://developer.gnome.org/gio/stable/GFile.html#g-file-copy
[2] https://developer.gnome.org/gdata/unstable/GDataDocumentsQuery.html#gdata-documents-query-new-with-limits
[3] https://developer.gnome.org/gdata/unstable/GDataDocumentsService.html#gdata-documents-service-query-documents
[4] https://developer.gnome.org/gdata/unstable/GDataQuery.html#gdata-query-next-page
Comment 5 Debarshi Ray 2017-02-17 09:13:12 UTC
(In reply to Debarshi Ray from comment #4)
> There is g_file_copy and g_file_copy_async/finish [1]. It uses the
> 'progress_callback' to notify the caller as chunks of bytes are copied from
> source to destination.

Note that the way things stand at the moment, g_file_copy_async is not introspectable due to the progress_callback. See bug 746111
Comment 6 Debarshi Ray 2017-02-17 09:17:55 UTC
(In reply to Bastien Nocera from comment #1)
> (In reply to Debarshi Ray from comment #0)
> > More importantly, the synchronous functions are not usable from inside a
> > threaded path because they get stuck and never return. As far as I can tell,
> > this is due to not using a thread default GMainContext. Again, something
> > that is typical in GIO-land, when a synchronous method is implemented in
> > terms of its asynchronous counterpart.
> 
> This is a plain bug, test case would be useful. I'm guessing it's a problem
> with the async machinery that doesn't check for whether the dispatch is done
> from the right thread.
> 
> Please file a separate bug with a test case and we can look into it.

This is quite obvious if you grep for 'grl_' in gnome-photos or gnome-online-miners. You'll see how it is worked around. It's quite easy to reproduce the problem if you replace the sync-implemented-by-async-wrapped-by-thread-default-context workarounds with the sync variants of the Grilo API.

But, sure, I will arrange a test case and file a separate bug.
Comment 7 Debarshi Ray 2017-09-05 14:32:40 UTC
(In reply to Bastien Nocera from comment #1)
> (In reply to Debarshi Ray from comment #0)
> > It would be nice if Grilo's asynchronous functions had a idiomatic GIO-like
> > pattern with GCancellables, GAsyncReadyCallbacks, etc..
> > 
> > More importantly, the synchronous functions are not usable from inside a
> > threaded path because they get stuck and never return. As far as I can tell,
> > this is due to not using a thread default GMainContext. Again, something
> > that is typical in GIO-land, when a synchronous method is implemented in
> > terms of its asynchronous counterpart.
> 
> This is a plain bug, test case would be useful. I'm guessing it's a problem
> with the async machinery that doesn't check for whether the dispatch is done
> from the right thread.
> 
> Please file a separate bug with a test case and we can look into it.

Filed bug 787312. Although I must say that the problem should have been obvious to anybody with a basic understanding of sync/async variants work in GIO.
Comment 8 GNOME Infrastructure Team 2018-09-24 09:41:41 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/grilo/issues/81.