[packagekit] Callbacks on script completion/task finish

Richard Hughes hughsient at gmail.com
Tue Nov 20 09:35:47 PST 2007

On Tue, 2007-11-20 at 14:22 +0100, Tom Parker wrote:
> Got a few ideas about how to do this, all of which have problems
> 1) Write my own version of pk_backend_spawn_helper that calls my C
> function when we get the finished signal, before doing all the tidy-up
> stuff. Can possibly be made less awful by re-using as many of the
> little functions in pk-backend.c as possible.

Not a good idea IMO.

> 2) Add another argument to pk_backend_spawn_helper.

Probably the best in your list, but see below.

> 3) Add some form of "callback-on-finish" support, either to
> pk_backend_finished or to pk_backend_spawn_finished_cb

Well, my initial thought was to just hook up the "finished" signal
handler, but thinking about it, PkEngine will delete the backend
instance a few seconds after the finished signal is emitted which is
probably half way through your new index rebuild. What you really want
to do is "wait and continue" like you suggest, indicating a callback is

> 4) Figure out how to implement the C function in python, and just get
> the update script to call that (but that will be pretty slow for the
> stuff I might want to do in C).

Nahh, lets fix the problem, not work around it :-)

What we need to do is think more abstract, i.e. have a function:

pk_backend_set_finished_spawn_thread (PkBackend *backend,
PkBackendThreadFunc func)
This would set backend->priv->external_callback = func.
That is run after we delete the spawn object in

We should only run backend->priv->external_callback(backend) if:

1. backend->priv->external_callback is non-NULL (need to set to NULL in
2. and only if backend->priv->exit == PK_EXIT_ENUM_SUCCESS (else we have
two error paths)
3. we run it with pk_backend_thread_create and return

This lets us chain the transaction and still do the right thing wrt
emitting errors and sending the correct signals.

Of course, this is a whole lot more complicated because the C function
has to be threaded to avoid locking the daemon... I think we need to
return from pk_backend_spawn_finished_cb without sending finished after
we've set up the thread of the external callback and rely on the thread
callback to emit pk_backend_finished.

This means we can run any backend with it's main spawned command and
then run a thread callback after the main task has completed. I'm
guessing this is quite useful for other backend dudes too.


More information about the PackageKit mailing list