Skip to content

bpo-29569: threading.Timer class: Continue periodical execution till action return True #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

slytomcat
Copy link

I think that functionality of threading.Timer class can be easily extended to generate the sequence of runs with specified period. The idea comes from the GLib.timeout_add function.

http://bugs.python.org/issue29569

As most current CB functions that are used in Timer returns nothing (None) they will run only once as earlier. Only functions that returns True will continue their periodical execution.

There are two ways to stop such continues execution:

  • Return something that is not True from action function,
  • Call cancel method of Timer class.

Changed method run should look like:

    def run(self):
        """Continue execution after wait till function returns True"""
        while(not self.finished.wait(self.interval)):
            if not self.function(*self.args, **self.kwargs):
                break
        self.finished.set()

@slytomcat
Copy link
Author

slytomcat commented Feb 20, 2017

It is reopened (due to need to reorganize my clonned repo) CR #121

@slytomcat
Copy link
Author

Closed after discussion on the issue.

@slytomcat slytomcat closed this Jun 6, 2017
akruis pushed a commit to akruis/cpython that referenced this pull request Dec 27, 2018
Use/implement tp_dealloc/tp_new/tp_free according to the latest C-API
documentation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants