Title: Avoid timer drift during long callbacks by greglucas · Pull Request #29023 · matplotlib/matplotlib · GitHub
Open Graph Title: Avoid timer drift during long callbacks by greglucas · Pull Request #29023 · matplotlib/matplotlib
X Title: Avoid timer drift during long callbacks by greglucas · Pull Request #29023 · matplotlib/matplotlib
Description: PR summary Updating the interval or single_shot attributes of a timer would call the underlying timer update functions regardless of if a new value was present or not. This caused issues in animations that set the interval to the same value in each iteration of the loop and when a long-running function was taking place this would cause the timers to drift. Note that even with the interval/single_shot updates, Tk was still drifting so we need to update that repeating timer code to avoid the time it takes within the callback itself. ping @richardsheridan for thoughts/suggestions on the Tk updates. closes #28647 alternative to #28997 Example to test with from the main issue. All backends before this produced ~300ms, all backends produce ~200ms after these updates for me. import matplotlib.pyplot as plt import numpy as np from matplotlib import animation def update(frame): if len(frame) < 2: return [] diff = np.diff(frame) avg.set_text(avg_txt.format(diff.mean()*1e3)) cur.set_text(cur_txt.format(diff[-1]*1e3)) return [avg, cur] def frame(): times = deque(maxlen=100) while True: time.sleep(0.1) times.append(time.perf_counter()) yield times fig, ax = plt.subplots(figsize=(1,1)) ax.axis('off') avg_txt = 'avg: {:.3g} ms' cur_txt = 'cur: {:.3g} ms' avg = ax.text(0.5, 0.75, avg_txt.format(0), va='center', ha='center') cur = ax.text(0.5, 0.25, cur_txt.format(0), va='center', ha='center') anim = animation.FuncAnimation(fig, update, frame, repeat=False, cache_frame_data=False, interval=200) PR checklist "closes #0000" is in the body of the PR description to link the related issue new and changed code is tested [n/a] Plotting related features are demonstrated in an example [n/a] New Features and API Changes are noted with a directive and release note [n/a] Documentation complies with general and docstring guidelines
Open Graph Description: PR summary Updating the interval or single_shot attributes of a timer would call the underlying timer update functions regardless of if a new value was present or not. This caused issues in animati...
X Description: PR summary Updating the interval or single_shot attributes of a timer would call the underlying timer update functions regardless of if a new value was present or not. This caused issues in animati...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/29023
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:38acd5ca-617d-9374-92a6-9fce77bde4b7 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | C42C:24C7F8:770A30:A67914:6A538BCB |
| html-safe-nonce | 77b6c340c26095c064663d31490e6af2144a023ddcfb19bb783bec879e6f69d5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNDJDOjI0QzdGODo3NzBBMzA6QTY3OTE0OjZBNTM4QkNCIiwidmlzaXRvcl9pZCI6IjI0MjQ1ODgxMjM2MDg2ODE0MTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 22d432c9f415e08d7410b4a113611370e2ac605e0c8f0527cf187cd92f7c2bb3 |
| hovercard-subject-tag | pull_request:2146406870 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/matplotlib/matplotlib/pull/29023/files |
| twitter:image | https://avatars.githubusercontent.com/u/12417828?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/12417828?s=400&v=4 |
| og:image:alt | PR summary Updating the interval or single_shot attributes of a timer would call the underlying timer update functions regardless of if a new value was present or not. This caused issues in animati... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width