Merge lp://staging/~erigami/dockmanager/workrave-helper into lp://staging/dockmanager

Proposed by Erigami
Status: Merged
Merged at revision: 70
Proposed branch: lp://staging/~erigami/dockmanager/workrave-helper
Merge into: lp://staging/dockmanager
Diff against target: 237 lines (+228/-0)
2 files modified
metadata/workrave_helper.py.info (+6/-0)
scripts/workrave_helper.py (+222/-0)
To merge this branch: bzr merge lp://staging/~erigami/dockmanager/workrave-helper
Reviewer Review Type Date Requested Status
Rico Tzschichholz Approve
Erigami (community) Needs Resubmitting
Michal Hruby (community) Approve
Review via email: mp+37417@code.staging.launchpad.net

Description of the change

Provides a helper for Workrave. See the blueprint for what the helper does.

To post a comment you must log in.
Revision history for this message
Michal Hruby (mhr3) wrote :

Please add the "DBusName" key to the info file - by using it, the script will only be run when that particular name is live on the bus (saves memory)

review: Needs Fixing
71. By Erigami

Added DBusName field to info file, as requested in code review.

Revision history for this message
Erigami (erigami) wrote :

I've added the DBusName key to the info file.

review: Needs Resubmitting
Revision history for this message
Rico Tzschichholz (ricotz) wrote :

* please add a license header to your code like all other helpers have.
* remove all debugging and dead code. Of course comments are welcome and should stay.
* use "print ..." for important debug outputs.
* for resetting ui make use of self.reset_tooltip(), self.reset_badge(), self.reset_icon(),
  ...

review: Needs Fixing
72. By Erigami

- Added license header
- Removed logging

Revision history for this message
Erigami (erigami) wrote :

Made fixes requested by Rico.

review: Needs Resubmitting
Revision history for this message
Rico Tzschichholz (ricotz) wrote :

@Erigami: Thanks for cleaning this up.

I haven't tested it since I don't use Workrave, but I think there a some problems.

What is the reason for these two classes WorkraveWatcher and WorkraveItem? Why not merging them together?

review: Needs Information
Revision history for this message
Rico Tzschichholz (ricotz) wrote :

This is most likely generating a leak every time the DockItem appears/changes:
    gobject.timeout_add(5000, self.__poll_workrave)
    gobject.timeout_add(1000, self.__update_ui)
You need to remove these timers if they aren't needed anymore and prevent adding them multiple times.

review: Needs Fixing
Revision history for this message
Erigami (erigami) wrote :

> What is the reason for these two classes WorkraveWatcher and WorkraveItem? Why
> not merging them together?

The WorkraveItem encapsulates the UI goo for the dock item - ideally I'd just use a DockItem, but it's missing set_message(). The Watcher receives callbacks from timers and updates the UI.

Revision history for this message
Erigami (erigami) wrote :

> This is most likely generating a leak every time the DockItem appears/changes:
> gobject.timeout_add(5000, self.__poll_workrave)
> gobject.timeout_add(1000, self.__update_ui)
> You need to remove these timers if they aren't needed anymore and prevent
> adding them multiple times.

I don't think they cause a memory leak, since on_service_change() is called once on startup. If there are any changes in the Workrave interface, then DockManager should stop the helper, right?

Is there something that I'm missing?

review: Needs Resubmitting
Revision history for this message
Michal Hruby (mhr3) wrote :

Looks good to me.

review: Approve
Revision history for this message
Michal Hruby (mhr3) wrote :

> > This is most likely generating a leak every time the DockItem
> appears/changes:
> > gobject.timeout_add(5000, self.__poll_workrave)
> > gobject.timeout_add(1000, self.__update_ui)
> > You need to remove these timers if they aren't needed anymore and prevent
> > adding them multiple times.
>
> I don't think they cause a memory leak, since on_service_change() is called
> once on startup. If there are any changes in the Workrave interface, then
> DockManager should stop the helper, right?
>
> Is there something that I'm missing?

Docky doesn't kill the helpers when their DBusName disappears. Rico probably meant a race if Workrave disappears from the bus and reappears in less than 1 second (or 5 in the other callback). You should remove the timers using "glib.source_remove(timer_id)".

Revision history for this message
Erigami (erigami) wrote :

> > I don't think they cause a memory leak, since on_service_change() is called
> > once on startup. If there are any changes in the Workrave interface, then
> > DockManager should stop the helper, right?
...
> Docky doesn't kill the helpers when their DBusName disappears. Rico probably
> meant a race if Workrave disappears from the bus and reappears in less than 1
> second (or 5 in the other callback). You should remove the timers using
> "glib.source_remove(timer_id)".

When I run DockManager from the console (and it's talking to AWN), it emits a message on the console telling me that the process has been killed.

The callbacks also return False when the connected flag is set to false, so they deregister themselves on the poll after the Workrave object disappears from dbus.

Revision history for this message
Robert Dyer (psybers) wrote :

The point is that not every implementation that uses DockManager (read: Docky) makes use of the daemon and behaves exactly the same.

So to be super safe, you need to assume that some implementations will not kill/restart the script and thus your code will wind up leaking.

Take a look at other helpers that use timers to see how to properly remove the stale timers.

Revision history for this message
Erigami (erigami) wrote :

I'll take Michal's suggestion and explicitly deregister timers with glib.source_remove().

Is there any doc on the lifecycle I should expect a helper to have? I've run against Docky and AWN/DockManager, but it sounds like there's more going on than I've seen.

Revision history for this message
Robert Dyer (psybers) wrote :

Eventually, everything will most likely use the DockManager daemon. The reason Docky does not use it (currently) is because this all started with Docky's helpers. We then decided to generalize it so it could be shared with AWN (and anything else that wants to use it). So AWN's implementation has from the start used the daemon while Docky's is using its original, custom implementation.

So you are already aware of everything. From a program perspective just consider your helper as a daemon that runs all the time. If your code works properly for that, it will work in every case.

Revision history for this message
Erigami (erigami) wrote :

Thanks Robert.

73. By Erigami

Move onto gobject.source_remove() for timers

Revision history for this message
Erigami (erigami) wrote :

The timers are now cleared explicitly.

review: Needs Resubmitting
Revision history for this message
Erigami (erigami) wrote :

Bump.

Revision history for this message
Rico Tzschichholz (ricotz) wrote :

@Erigami: If you gave it a spin with docky then I think we are good here.

review: Approve
Revision history for this message
Erigami (erigami) wrote :

> @Erigami: If you gave it a spin with docky then I think we are good here.

Will do. Thanks.

Revision history for this message
Erigami (erigami) wrote :

I gave it a go with docky, and it works as expected.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches

to status/vote changes: