Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Use async function in Python programs #125

Closed
ghost opened this issue May 21, 2016 · 3 comments
Closed

Question: Use async function in Python programs #125

ghost opened this issue May 21, 2016 · 3 comments

Comments

@ghost
Copy link

ghost commented May 21, 2016

Hi there,

There is a lack of documentation and examples on the use of async function for the python bindings. As i don't find any solution, i think it's better to ask directly. Anyway, i don't think I'm alone in this case.

For my project, i use PackageKit v1.0 python bindings. In order to have a non blocking refresh cache or install software operation, i use the native Thread class from python libs. But, as far as i know _async methods in PKit work properly, but i don't know how to achieve my goal.

With two callbacks declared : one follows PackageKitGlib.ProgressCallback signature and the other one follow Gio.AsyncReadyCallback

  • For PackageKitGlib.ProgressCallback
    def transmit_repository_update_status(self, progress, type, user_data):
        self.panel.set_repository_update_status(progress.props.percentage)
  • For Gio.AsyncReadyCallback
    def async_ready(self, source, res, data):
        print(str(source) + str(res) + str(data))

The function call is :

self.refresh_cache_async(False, self.canceller, callback_update_repository, None, 
async_ready, None)

The result is a TypeError: expected tuple for callback user_data exception. As far as i know, i can't understand why.

After searching for a solution of the web since a couple of month, i gave up and still used native threads. But this is not a good solution.

Can you provide an example for this kind of problem or anything else that can help the developers ?
Anyway, does this question will have to be asked to the mailling list of developers that maintain the bindings ?

@ghost ghost changed the title Question : Use aync function in Python programs Question : Use async function in Python programs May 21, 2016
@hughsie
Copy link
Collaborator

hughsie commented May 23, 2016

I think the mailing list is a much better place to ask these kind of questions; I'm not a huge python guru so I'm not sure how you'd handle that vfunc progress callback. My gut instinct is the scope attributes are wrong, but I'm not sure.

@ximion
Copy link
Collaborator

ximion commented May 23, 2016

You should do something like this:

pktask.refresh_cache_async (False, # force
                                            None,  # GCancellable
                                            self.on_pktask_progress,
                                            (None,), # user data
                                            self.on_pktask_finish,
                                            (None,));

This is not a PackageKit issue, rather a PyGObject weirdness.

@ximion ximion changed the title Question : Use async function in Python programs Question: Use async function in Python programs Jun 2, 2016
@ghost
Copy link
Author

ghost commented Jun 20, 2016

Ok thanks a lot, I'll try to write a script and publish it. :)

@ximion ximion closed this as completed Jun 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants