Skip to content
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

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

Closed
wants to merge 6 commits into from

Conversation

slytomcat
Copy link

@slytomcat slytomcat commented Feb 15, 2017

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.

It is my first contribution and I kindly ask to help me with required future actions.

Thanks

@slytomcat slytomcat changed the title threading.Timer class: Continue periodical execution till action retun True threading.Timer class: Continue periodical execution till action return True Feb 15, 2017
@slytomcat
Copy link
Author

I've fixed test for continuous execution of Timer class. Now check passed.

@andrewnester
Copy link
Contributor

I am wondering how it will influence existing code. Most of the functions currently used in Timer callback probably not returning True value. It means that they will be executed infinitely.

Maybe it's better to add some new argument like repeat_until which takes some callback indicating when to finish execution. By default it will have some value to indicate only 1 repeat of callback execution.

@slytomcat
Copy link
Author

No, exactly conversely - if function returns None or not True it will run only once.
The only returning True continues execution after next timeout.

@andrewnester
Copy link
Contributor

@slytomcat right, sorry, my bad

@slytomcat
Copy link
Author

codecov/patch — 81.25% of diff hit (target 100%) - anybody know how to fix it?

Lib/threading.py Outdated
if not self.finished.is_set():
self.function(*self.args, **self.kwargs)
"""Continue execution after wait until function returns True"""
while(not self.finished.wait(self.interval)):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to add test case when this is true. It might help you get 100% coverage

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. But: codecov/patch — 86.95% of diff hit (target 100%) - some red lines in Lib/test/test_threading.py.
I have no idea how to cover tests by tests =/

@slytomcat slytomcat changed the title threading.Timer class: Continue periodical execution till action return True bpo-29569: threading.Timer class: Continue periodical execution till action return True Feb 17, 2017
@slytomcat
Copy link
Author

I have to reorganize my cloned repo so the CR have to be reissued.

@slytomcat
Copy link
Author

Reopened CR: #191

akruis pushed a commit to akruis/cpython that referenced this pull request Sep 9, 2017
…ile clearing a thread state

If Python clears a thread state and a destructor or a weakref-callback runs Python code, Python used to create a new initial stub without clearing it later. This change reorders PyThreadState_Clear() to clear the PyStacklessState sub-structure last. A new test case for this problem uses thread local storage to execute a __del__-method.

https://bitbucket.org/stackless-dev/stackless/issues/121
(grafted from ede2ad2b32b917d364f523318a82c75d0df2a0e6)
akruis pushed a commit to akruis/cpython that referenced this pull request Sep 9, 2017
akruis pushed a commit to akruis/cpython that referenced this pull request Sep 9, 2017
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.

3 participants