Python - Constantly running an event handler without wxPython?Python: What OS am I running on?Is there a way to run Python on Android?How to get the filename without the extension from a path in Python?How do I check what version of Python is running my script?How to make a Python script standalone executable to run without ANY dependency?Why does Python code run faster in a function?wxPython combo.ComboCtrl event handling issuewxPython window immediately crashes/closes with Komodo on MacwxPython Ignore or Delete EventswxPython: Catching key events globally

Does the Long March-11 increase its thrust after clearing the launch tower?

Why does Sin[b-a] simplify to -Sin[a-b]?

Longest bridge/tunnel that can be cycled over/through?

Traversing Oceania: A Cryptic Journey

Does Disney no longer produce hand-drawn cartoon films?

Who are the Missing Members of this Noble Family?

How is the excise border managed in Ireland?

Active low-pass filters --- good to what frequencies?

What is the maximum number of net attacks that one can make in a round?

Is it possible for a vehicle to be manufactured without a catalytic converter?

Wooden cooking layout

How can I get an unreasonable manager to approve time off?

Is it legal for a bar bouncer to confiscate a fake ID

Why can I traceroute to this IP address, but not ping?

Meaning of 'lose their grip on the groins of their followers'

Getting UPS Power from One Room to Another

Is using 'echo' to display attacker-controlled data on the terminal dangerous?

Thread Pool C++ Implementation

What aircraft was used as Air Force One for the flight between Southampton and Shannon?

Second (easy access) account in case my bank screws up

Missing delay in heavyside step function

Extreme flexible working hours: how to get to know people and activities?

Why does logistic function use e rather than 2?

Has there been a multiethnic Star Trek character?



Python - Constantly running an event handler without wxPython?


Python: What OS am I running on?Is there a way to run Python on Android?How to get the filename without the extension from a path in Python?How do I check what version of Python is running my script?How to make a Python script standalone executable to run without ANY dependency?Why does Python code run faster in a function?wxPython combo.ComboCtrl event handling issuewxPython window immediately crashes/closes with Komodo on MacwxPython Ignore or Delete EventswxPython: Catching key events globally






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm currently attempting to write a script using Python 2.7 (on Windows 7) that displays notifications using the notification software Snarl. Making the connection to Snarl requires the pySnarl module (link). The pySnarl module includes and Event Handler that basically checks to see if the notification has been closed or clicked on by a user and allows the script to run a function if such an event has occurred. I'm trying to implement this, however I cannot seem to get the Event handler to constantly listen for a click. There is an example script written by the author of the module (link) which shows use of the event handler and it works perfectly, but it gets the event handler to listen for clicks by making use of wxPython's app.MainLoop() command. I can't do this because my script is GUIless, I just want to use Windows Task Scheduler to run it every now and then in the background. I've tried a while True loop to get the Event Handler method constantly running but it does nothing except consume heaps of CPU. Here is my script (in the code formatting because I can't post more than 2 links right now):



 http://pastebin.com/4udVehg1


TLDR; I want an Event Handler to listen for events but I don't know how to get it running without using wxPython's app.MainLoop() feature and I want my script to be GUIless.



Any help would be greatly appreciated.



Regards,
Jono.










share|improve this question






















  • Check out Twisted

    – alfasin
    Jul 21 '14 at 6:31

















0















I'm currently attempting to write a script using Python 2.7 (on Windows 7) that displays notifications using the notification software Snarl. Making the connection to Snarl requires the pySnarl module (link). The pySnarl module includes and Event Handler that basically checks to see if the notification has been closed or clicked on by a user and allows the script to run a function if such an event has occurred. I'm trying to implement this, however I cannot seem to get the Event handler to constantly listen for a click. There is an example script written by the author of the module (link) which shows use of the event handler and it works perfectly, but it gets the event handler to listen for clicks by making use of wxPython's app.MainLoop() command. I can't do this because my script is GUIless, I just want to use Windows Task Scheduler to run it every now and then in the background. I've tried a while True loop to get the Event Handler method constantly running but it does nothing except consume heaps of CPU. Here is my script (in the code formatting because I can't post more than 2 links right now):



 http://pastebin.com/4udVehg1


TLDR; I want an Event Handler to listen for events but I don't know how to get it running without using wxPython's app.MainLoop() feature and I want my script to be GUIless.



Any help would be greatly appreciated.



Regards,
Jono.










share|improve this question






















  • Check out Twisted

    – alfasin
    Jul 21 '14 at 6:31













0












0








0


1






I'm currently attempting to write a script using Python 2.7 (on Windows 7) that displays notifications using the notification software Snarl. Making the connection to Snarl requires the pySnarl module (link). The pySnarl module includes and Event Handler that basically checks to see if the notification has been closed or clicked on by a user and allows the script to run a function if such an event has occurred. I'm trying to implement this, however I cannot seem to get the Event handler to constantly listen for a click. There is an example script written by the author of the module (link) which shows use of the event handler and it works perfectly, but it gets the event handler to listen for clicks by making use of wxPython's app.MainLoop() command. I can't do this because my script is GUIless, I just want to use Windows Task Scheduler to run it every now and then in the background. I've tried a while True loop to get the Event Handler method constantly running but it does nothing except consume heaps of CPU. Here is my script (in the code formatting because I can't post more than 2 links right now):



 http://pastebin.com/4udVehg1


TLDR; I want an Event Handler to listen for events but I don't know how to get it running without using wxPython's app.MainLoop() feature and I want my script to be GUIless.



Any help would be greatly appreciated.



Regards,
Jono.










share|improve this question














I'm currently attempting to write a script using Python 2.7 (on Windows 7) that displays notifications using the notification software Snarl. Making the connection to Snarl requires the pySnarl module (link). The pySnarl module includes and Event Handler that basically checks to see if the notification has been closed or clicked on by a user and allows the script to run a function if such an event has occurred. I'm trying to implement this, however I cannot seem to get the Event handler to constantly listen for a click. There is an example script written by the author of the module (link) which shows use of the event handler and it works perfectly, but it gets the event handler to listen for clicks by making use of wxPython's app.MainLoop() command. I can't do this because my script is GUIless, I just want to use Windows Task Scheduler to run it every now and then in the background. I've tried a while True loop to get the Event Handler method constantly running but it does nothing except consume heaps of CPU. Here is my script (in the code formatting because I can't post more than 2 links right now):



 http://pastebin.com/4udVehg1


TLDR; I want an Event Handler to listen for events but I don't know how to get it running without using wxPython's app.MainLoop() feature and I want my script to be GUIless.



Any help would be greatly appreciated.



Regards,
Jono.







python python-2.7 wxpython python-2.x






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jul 21 '14 at 6:22









HeyItsJonoHeyItsJono

215




215












  • Check out Twisted

    – alfasin
    Jul 21 '14 at 6:31

















  • Check out Twisted

    – alfasin
    Jul 21 '14 at 6:31
















Check out Twisted

– alfasin
Jul 21 '14 at 6:31





Check out Twisted

– alfasin
Jul 21 '14 at 6:31












2 Answers
2






active

oldest

votes


















0














Found a solution. I just needed to run the following at the end of my script:



while event_handling is True:
win32gui.PumpMessages() # Check for events, needs to be sent a WM_QUIT message to stop, handled in disable_event_handling()
time.sleep(0.1) # Check every 0.1 seconds


Then on a event being activated just call the following function to stop the script checking for events:



main_thread_id = win32api.GetCurrentThreadId()
event_handling = True

def disable_event_handling(): # Puts a stop to the loop that checks for events
global event_handling
event_handling = False
win32api.PostThreadMessage(main_thread_id, win32con.WM_QUIT, 0, 0) # Sends a QUIT message to win32gui.PumpMessages(), without this it wouldn't stop checking for messages to pump
return event_handling


Thanks for all the help and suggestions guys c:






share|improve this answer






























    0














    Sounds like a job for PyPubSub : a package which provides a publish - subscribe Python API that facilitates event-based programming.



    Check it out: http://pubsub.sourceforge.net/



    Edit: PyPubSub is at https://github.com/schollii/pypubsub (since 2016)






    share|improve this answer

























    • Thanks for the tip, it looks interesting but I have no clue how I'd go about getting it integrated. The binding I'm using uses win32com.client.DispatchWithEvents() and a handler class with the events defined within. How would I go about using PyPubSub to make that class constantly be on the lookout for events?

      – HeyItsJono
      Jul 21 '14 at 8:54











    • All you need to do is set up a subscription and then when you want to send an "event", you publish it. The website has examples. There's also another package called PyDispatcher, which is an alternative to pubsub: pydispatcher.sourceforge.net

      – Mike Driscoll
      Jul 21 '14 at 13:59











    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f24858805%2fpython-constantly-running-an-event-handler-without-wxpython%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Found a solution. I just needed to run the following at the end of my script:



    while event_handling is True:
    win32gui.PumpMessages() # Check for events, needs to be sent a WM_QUIT message to stop, handled in disable_event_handling()
    time.sleep(0.1) # Check every 0.1 seconds


    Then on a event being activated just call the following function to stop the script checking for events:



    main_thread_id = win32api.GetCurrentThreadId()
    event_handling = True

    def disable_event_handling(): # Puts a stop to the loop that checks for events
    global event_handling
    event_handling = False
    win32api.PostThreadMessage(main_thread_id, win32con.WM_QUIT, 0, 0) # Sends a QUIT message to win32gui.PumpMessages(), without this it wouldn't stop checking for messages to pump
    return event_handling


    Thanks for all the help and suggestions guys c:






    share|improve this answer



























      0














      Found a solution. I just needed to run the following at the end of my script:



      while event_handling is True:
      win32gui.PumpMessages() # Check for events, needs to be sent a WM_QUIT message to stop, handled in disable_event_handling()
      time.sleep(0.1) # Check every 0.1 seconds


      Then on a event being activated just call the following function to stop the script checking for events:



      main_thread_id = win32api.GetCurrentThreadId()
      event_handling = True

      def disable_event_handling(): # Puts a stop to the loop that checks for events
      global event_handling
      event_handling = False
      win32api.PostThreadMessage(main_thread_id, win32con.WM_QUIT, 0, 0) # Sends a QUIT message to win32gui.PumpMessages(), without this it wouldn't stop checking for messages to pump
      return event_handling


      Thanks for all the help and suggestions guys c:






      share|improve this answer

























        0












        0








        0







        Found a solution. I just needed to run the following at the end of my script:



        while event_handling is True:
        win32gui.PumpMessages() # Check for events, needs to be sent a WM_QUIT message to stop, handled in disable_event_handling()
        time.sleep(0.1) # Check every 0.1 seconds


        Then on a event being activated just call the following function to stop the script checking for events:



        main_thread_id = win32api.GetCurrentThreadId()
        event_handling = True

        def disable_event_handling(): # Puts a stop to the loop that checks for events
        global event_handling
        event_handling = False
        win32api.PostThreadMessage(main_thread_id, win32con.WM_QUIT, 0, 0) # Sends a QUIT message to win32gui.PumpMessages(), without this it wouldn't stop checking for messages to pump
        return event_handling


        Thanks for all the help and suggestions guys c:






        share|improve this answer













        Found a solution. I just needed to run the following at the end of my script:



        while event_handling is True:
        win32gui.PumpMessages() # Check for events, needs to be sent a WM_QUIT message to stop, handled in disable_event_handling()
        time.sleep(0.1) # Check every 0.1 seconds


        Then on a event being activated just call the following function to stop the script checking for events:



        main_thread_id = win32api.GetCurrentThreadId()
        event_handling = True

        def disable_event_handling(): # Puts a stop to the loop that checks for events
        global event_handling
        event_handling = False
        win32api.PostThreadMessage(main_thread_id, win32con.WM_QUIT, 0, 0) # Sends a QUIT message to win32gui.PumpMessages(), without this it wouldn't stop checking for messages to pump
        return event_handling


        Thanks for all the help and suggestions guys c:







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jul 25 '14 at 9:54









        HeyItsJonoHeyItsJono

        215




        215























            0














            Sounds like a job for PyPubSub : a package which provides a publish - subscribe Python API that facilitates event-based programming.



            Check it out: http://pubsub.sourceforge.net/



            Edit: PyPubSub is at https://github.com/schollii/pypubsub (since 2016)






            share|improve this answer

























            • Thanks for the tip, it looks interesting but I have no clue how I'd go about getting it integrated. The binding I'm using uses win32com.client.DispatchWithEvents() and a handler class with the events defined within. How would I go about using PyPubSub to make that class constantly be on the lookout for events?

              – HeyItsJono
              Jul 21 '14 at 8:54











            • All you need to do is set up a subscription and then when you want to send an "event", you publish it. The website has examples. There's also another package called PyDispatcher, which is an alternative to pubsub: pydispatcher.sourceforge.net

              – Mike Driscoll
              Jul 21 '14 at 13:59















            0














            Sounds like a job for PyPubSub : a package which provides a publish - subscribe Python API that facilitates event-based programming.



            Check it out: http://pubsub.sourceforge.net/



            Edit: PyPubSub is at https://github.com/schollii/pypubsub (since 2016)






            share|improve this answer

























            • Thanks for the tip, it looks interesting but I have no clue how I'd go about getting it integrated. The binding I'm using uses win32com.client.DispatchWithEvents() and a handler class with the events defined within. How would I go about using PyPubSub to make that class constantly be on the lookout for events?

              – HeyItsJono
              Jul 21 '14 at 8:54











            • All you need to do is set up a subscription and then when you want to send an "event", you publish it. The website has examples. There's also another package called PyDispatcher, which is an alternative to pubsub: pydispatcher.sourceforge.net

              – Mike Driscoll
              Jul 21 '14 at 13:59













            0












            0








            0







            Sounds like a job for PyPubSub : a package which provides a publish - subscribe Python API that facilitates event-based programming.



            Check it out: http://pubsub.sourceforge.net/



            Edit: PyPubSub is at https://github.com/schollii/pypubsub (since 2016)






            share|improve this answer















            Sounds like a job for PyPubSub : a package which provides a publish - subscribe Python API that facilitates event-based programming.



            Check it out: http://pubsub.sourceforge.net/



            Edit: PyPubSub is at https://github.com/schollii/pypubsub (since 2016)







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 24 at 19:01









            Oliver

            16.2k32648




            16.2k32648










            answered Jul 21 '14 at 7:04









            user2963623user2963623

            1,9501924




            1,9501924












            • Thanks for the tip, it looks interesting but I have no clue how I'd go about getting it integrated. The binding I'm using uses win32com.client.DispatchWithEvents() and a handler class with the events defined within. How would I go about using PyPubSub to make that class constantly be on the lookout for events?

              – HeyItsJono
              Jul 21 '14 at 8:54











            • All you need to do is set up a subscription and then when you want to send an "event", you publish it. The website has examples. There's also another package called PyDispatcher, which is an alternative to pubsub: pydispatcher.sourceforge.net

              – Mike Driscoll
              Jul 21 '14 at 13:59

















            • Thanks for the tip, it looks interesting but I have no clue how I'd go about getting it integrated. The binding I'm using uses win32com.client.DispatchWithEvents() and a handler class with the events defined within. How would I go about using PyPubSub to make that class constantly be on the lookout for events?

              – HeyItsJono
              Jul 21 '14 at 8:54











            • All you need to do is set up a subscription and then when you want to send an "event", you publish it. The website has examples. There's also another package called PyDispatcher, which is an alternative to pubsub: pydispatcher.sourceforge.net

              – Mike Driscoll
              Jul 21 '14 at 13:59
















            Thanks for the tip, it looks interesting but I have no clue how I'd go about getting it integrated. The binding I'm using uses win32com.client.DispatchWithEvents() and a handler class with the events defined within. How would I go about using PyPubSub to make that class constantly be on the lookout for events?

            – HeyItsJono
            Jul 21 '14 at 8:54





            Thanks for the tip, it looks interesting but I have no clue how I'd go about getting it integrated. The binding I'm using uses win32com.client.DispatchWithEvents() and a handler class with the events defined within. How would I go about using PyPubSub to make that class constantly be on the lookout for events?

            – HeyItsJono
            Jul 21 '14 at 8:54













            All you need to do is set up a subscription and then when you want to send an "event", you publish it. The website has examples. There's also another package called PyDispatcher, which is an alternative to pubsub: pydispatcher.sourceforge.net

            – Mike Driscoll
            Jul 21 '14 at 13:59





            All you need to do is set up a subscription and then when you want to send an "event", you publish it. The website has examples. There's also another package called PyDispatcher, which is an alternative to pubsub: pydispatcher.sourceforge.net

            – Mike Driscoll
            Jul 21 '14 at 13:59

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f24858805%2fpython-constantly-running-an-event-handler-without-wxpython%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript