Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8502705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:33:33+00:00 2026-06-11T01:33:33+00:00

I’m trying to make a simple Unix desktop application which uses the pynotify notification

  • 0

I’m trying to make a simple Unix desktop application which uses the pynotify notification system to show users some alerts and allow them to launch relevant applications from a button on placed on the alert.

Here is the relevant simplified code :

import subprocess, pynotify, gobject, gtk

class Notifier():
    def __init__(self):
        pynotify.init('Notifications')
        n = pynotify.Notification("Some stuff")
        n.add_action("action", "Action", self.action_callback)
        n.show()
        gtk.main()

    def action_callback(self, n, action):
        subprocess.Popen(['ls', '/'])

if __name__ == '__main__':
    Notifier()

This works fine (it shows a notification popup with an “Action” button which triggers a ls / when activated) until I actually try to put the notification part into a loop (I need to regularly poll a server to get notifications to then show).

I’ve tried this :

import subprocess, pynotify, gobject, gtk

class Notifier():
    def __init__(self):
        pynotify.init('Notifications')
        gobject.timeout_add(0, self.main)
        gtk.main()

    def action_callback(self, n, action):
        subprocess.Popen(['ls', '/'])

    def main(self):
        n = pynotify.Notification("Some stuff")
        n.add_action("action", "Action", self.action_callback)
        n.show()
        gobject.timeout_add(10000, self.main)

if __name__ == '__main__':
    Notifier()

but for some reason the “action_callback” function is not called anymore when clicking on the “Action” button.

It seems this is an issue with the way I use the Gtk main loop. Doing something like this makes the function to actually be triggered :

import subprocess, pynotify, gobject, gtk

class Notifier():
    def __init__(self):
        pynotify.init('Notifications')
        self.main()

    def action_callback(self, n, action):
        subprocess.Popen(['ls', '/'])

    def main(self):
        n = pynotify.Notification("Some stuff")
        n.add_action("action", "Action", self.action_callback)
        n.show()
        gobject.timeout_add(10000, self.main)
        gtk.main()

if __name__ == '__main__':
    Notifier()

but of course this is no proper solution and I quickly get a “maximum recursion depth exceeded” Python RuntimeError. However it shows that changing the place of the gtk.main() call has an incidence.

I’ve tried to look at Gtk and Pygtk documentation about the main loop but ultimatelly didn’t find a solution.

So my question is : what’s the proper thing to do and what is the logic behind it ?

TL;DR : If I don’t put gtk.main() in the same function which display the notification, the action_callback function is not triggered when it should. Since this function needs to be put in the gtk mainloop, I’m then stuck with having the gtk mainloop calling itself or the action_callback function not being triggered.

Thanks in advance for any help 😉

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:33:34+00:00Added an answer on June 11, 2026 at 1:33 am

    The problem here is that pynotify has an bug with callbacks on unreferenced objects. In your first snippet, n gets unreferenced (assuming reference counting in cPython) when the main() function exits.
    Unfortunately, this means that the notification object is destroyed, and the action is not called (although your notification daemon will still show the notification).

    The work-around to this is to keep a reference to that notification.
    The simplest thing to do is to take your first snippet and change n = pynotify.Notification to self.last_notification = n = pynotify.Notication.

    If you have multiple notifications, you’ll need to throw them in a list or a set, but then you’ll need to make sure they get deleted, both in the case where the action is triggered, and when the timeout expires.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have just tried to save a simple *.rtf file with some websites and
I'm trying to select an H1 element which is the second-child in its group
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.