Alternative to time.sleep(n) ?

  • Obviously this does not work for time delay between two commands e.g. :-


    Code
    self.actionA
    time.sleep(5)
    self.actionB


    What is the simple alternative ? Any code examples reference please ?


    Regards, pcd.

  • normaly the should work. but it is not nice, because it blocks e2 while this 5seconds.





    this will print each 5 sec. 'time ends'

    Einmal editiert, zuletzt von 3c5x9 ()

  • Thank you very much. It works. :smiling_face:


    Example code :-


    Code
    def main(session, **kwargs):
            print "In main"
            delay = Test(session, None)
            f = delay.starttimer()
            session.openWithCallback(test, MessageBox, _("Test-Messagebox2?"), timeout = 10)
            f = delay.stoptimer()       
            session.openWithCallback(test, MessageBox, _("Test-Messagebox1?"), timeout = 10)


    It is interesting that the first command has to be listed second !


    Regards, pcd.

  • Zitat

    Original von pcd
    It is interesting that the first command has to be listed second !


    Unfortunately this is not true. Of course code is still executed in order but what you're experiencing is the following:
    - First Messagebox is created and shown, Timer in Messagebox counts down
    - Without any delay the second one is created and also shown, Timer of first Messagebox stops counting down; second one does count down
    - Second Messagebox times out
    - Timer of First Messagebox counts down again
    - First Messagebox times out


    This occurs to the user as if the second Messagebox would be shown first although this is actually not true.
    I experienced similar Problems with SimpleRSS when the User gets informed about the updates done in Background. When an error occurs a new Messagebox is created and after this times out or is hidden the first one is shown again with the countdown still showing the same timeout as before.


    And Reichi is also right as the timer is not called as singleShot.


    PS: My Comment is based on observations I made while developing myself, I did not try the actual samples but I checked its contents :winking_face:

    Homescreen eurer Apple-Geräte noch nicht voll genug?


    dreaMote: Fernbedienung für Dreamboxen
    Mobile WOL: Wake-on-LAN Client für iOS mit optionalem Widget
    My Home Remote: Fernkontrolle für Homematic CCU/CCU2 optimiert für mobile Benutzung