GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-29569: threading.Timer class: Continue periodical execution till action return True by slytomcat · Pull Request #121 · python/cpython

Conversation

@slytomcat

@slytomcat slytomcat commented Feb 15, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@slytomcat
Change in threading.Timer class: Continue periodical execution until …
7895315
…action returns True.
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Feb 15, 2017
@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
Fix for threading tests for Timer class
cfac9a1
@slytomcat

slytomcat commented Feb 15, 2017

Copy link
Copy Markdown
Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andrewnester

andrewnester commented Feb 15, 2017

Copy link
Copy Markdown
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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@slytomcat

slytomcat commented Feb 15, 2017

Copy link
Copy Markdown
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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andrewnester

andrewnester commented Feb 15, 2017

Copy link
Copy Markdown
Contributor

@slytomcat right, sorry, my bad

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@slytomcat

slytomcat commented Feb 15, 2017

Copy link
Copy Markdown
Author

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

slytomcat and andrewnester reacted with confused emoji
All reactions
  • 😕 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

andrewnester
andrewnester reviewed Feb 16, 2017
View reviewed changes
Comment thread Lib/threading.py
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)):

@andrewnester andrewnester Feb 16, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@slytomcat slytomcat Feb 16, 2017

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

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 =/

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
slytomcat and others added 4 commits February 16, 2017 10:27
@slytomcat
Test coverage increased
178568b
@slytomcat
fix docs
e25ab6a
@slytomcat
increased test coverage
ab382d0
@slytomcat
Merge pull request #1 from python/master
b19dcb8
sync with master
@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

slytomcat commented Feb 20, 2017

Copy link
Copy Markdown
Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@slytomcat slytomcat closed this Feb 20, 2017
@slytomcat slytomcat mentioned this pull request Feb 20, 2017
bpo-29569: threading.Timer class: Continue periodical execution till action return True #191
Closed
@slytomcat

slytomcat commented Feb 20, 2017

Copy link
Copy Markdown
Author

Reopened CR: #191

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

akruis pushed a commit to akruis/cpython that referenced this pull request Sep 9, 2017
Anselm Kruis
Issue python#121: Fix a reference leak, if Python runs Python code wh…
ade1fae
…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
Anselm Kruis
merge 3.4-slp (Stackless python#121)
3d7d227
akruis pushed a commit to akruis/cpython that referenced this pull request Sep 9, 2017
Anselm Kruis
merge 3.3-slp (Stackless python#121)
a740da9
@gvanrossum gvanrossum mentioned this pull request Aug 22, 2023
heap-use-after-free in _PyFunction_LookupByVersion #108253
Closed
This was referenced Feb 11, 2025
segmentfault when pip installing setuptools #129992
Closed
segmentfault when pip installing setuptools #129993
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@andrewnester andrewnester andrewnester left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@slytomcat @andrewnester @the-knights-who-say-ni
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.