[Sugar-devel] Communication between two Activities
James Cameron
quozl at laptop.org
Wed May 20 19:06:53 EDT 2015
On Wed, May 20, 2015 at 10:43:23AM -0300, Gustavo Duarte wrote:
> Notificator: There is a Sugar Activity who shows Notification messages
> for the kid.
>
> Daemon: There is an script running on cron, who get new notification
> from a Server.
>
> I need communicate the Daemon with the Notificator, so when Daemon
> receive a new notification from Server, it'll send a signal to
> Notificator.
>
> Notificator when receive the signal, should refresh a widget.
>
> I know a way to do that, using system signals, but i wonder if Sugar
> has another way to achieve that.
What you describe is interprocess communication.
Sugar uses several methods for communication with system daemons.
The most frequently coded is D-Bus.
http://en.wikipedia.org/wiki/D-Bus
Other methods in Python are
https://docs.python.org/2/library/ipc.html
You can use files, as Gonzalo says, but try to place them in a path
that does not cause writes to disk; e.g. /tmp ... otherwise sometimes
the kernel will reschedule the process that is writing, and this can
slow performance.
My preference for your scenario is signals:
1. Notificator calls os.getpid and writes to /tmp/notificator.pid
2. Notificator calls signal.signal to request a callback on SIGUSR1,
3. Daemon reads /tmp/notificator.pid and calls os.kill(pid, SIGUSR1),
kill(1), or kill(3) to send signal.
An example here:
http://dev.laptop.org/git/projects/runin/tree/runin-gtk
Signals become more complex if the communication is complex, and there
are a limited number of different signals. That's when I would
suggest D-Bus.
--
James Cameron
http://quozl.linux.org.au/
More information about the Sugar-devel
mailing list