René's URL Explorer Experiment


Title: Tkagg event loop throws error on window close · Issue #19940 · matplotlib/matplotlib · GitHub

Open Graph Title: Tkagg event loop throws error on window close · Issue #19940 · matplotlib/matplotlib

X Title: Tkagg event loop throws error on window close · Issue #19940 · matplotlib/matplotlib

Description: I have some code that continuously updates an MPL plot, and used fig.canvas.start_event_loop(0.0001) to listen for keyboard input. As of MPL 3.4, this code is broken in two ways: Commit c53570d converts the timeout to int milliseconds. T...

Open Graph Description: I have some code that continuously updates an MPL plot, and used fig.canvas.start_event_loop(0.0001) to listen for keyboard input. As of MPL 3.4, this code is broken in two ways: Commit c53570d con...

X Description: I have some code that continuously updates an MPL plot, and used fig.canvas.start_event_loop(0.0001) to listen for keyboard input. As of MPL 3.4, this code is broken in two ways: Commit c53570d con...

Opengraph URL: https://github.com/matplotlib/matplotlib/issues/19940

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Tkagg event loop throws error on window close","articleBody":"I have some code that continuously updates an MPL plot, and used `fig.canvas.start_event_loop(0.0001)` to listen for keyboard input. As of MPL 3.4, this code is broken in two ways:\r\n\r\n1. [Commit c53570d](https://github.com/matplotlib/matplotlib/commit/c53570db3e602d2855813fa76a971ae3b62d361a) converts the timeout to int milliseconds. This rounds down 0.0001 to 0 and fails to display the window at all. I might suggest `math.ceil(1000*timeout)` instead of `int(1000*timeout)`?\r\n2. After changing 0.0001 to 0.001 in my code, [Commit 630e806](https://github.com/matplotlib/matplotlib/commit/630e806ef7dfd0520490eeb85d2c866d8f8dca94) causes MPL to throw an error `invalid command name \"140668474408832stop_event_loop\" while executing \"140668474408832stop_event_loop\" (\"after\" script)` when closing the window before pausing the loop. Expected behavior would be for it to simply terminate the loop. It's a harmless error in the minimal code below (you can still launch new runs), but my full code updates using an `asyncio` event loop, which this behavior fails to exit, so this error prevents launching new runs in that case (`asyncio.run() cannot be called from a running event loop`). Not sure how to fix this one, but I'll note that using `fig.canvas.flush_events()` in my code instead of `start_event_loop` produces the desired behavior.\r\n\r\nNot sure if #2 is worth fixing given that `flush_events()` restores the desired behavior, but @richardsheridan suggested I post an issue in my comment on that commit. Minimal example below. Launch an MPL window and then close it before pausing to trigger the error:\r\n\r\n```\r\nfrom random import randint\r\nimport matplotlib, matplotlib.pyplot as plt\r\nfrom tkinter import *\r\n\r\nclass Visual:\r\n\trunning = False\r\n\t\r\n\t#Construct a launch button\r\n\tdef __init__(self):\r\n\t\tself.parent = Tk()\r\n\t\t\r\n\t\tself.runButton = Button(self.parent, text='Run', command=self.launchVisual, padx=10, pady=10)\r\n\t\tself.runButton.pack(fill=\"x\", side=TOP)\r\n\t\t\t\t\t\r\n\tdef start(self):\r\n\t\tself.runButton['text'] = 'Pause'\r\n\t\tself.runButton['command'] = self.stop\r\n\t\tself.running = True\r\n\t\t\r\n\t\twhile self.running:\r\n\t\t\tself.data.append(randint(0,100))\r\n\t\t\r\n\t\t\tself.line.set_ydata(self.data)\r\n\t\t\tself.line.set_xdata(range(len(self.data)))\r\n\t\t\tself.axes.relim()\r\n\t\t\tself.axes.autoscale_view(tight=False)\r\n\t\t\r\n\t\t\tif self.fig.stale: self.fig.canvas.draw_idle()\r\n\t\t\t\r\n\t\t\t#This rounds down to 0 and doesn't draw the window at all\r\n\t\t\t#self.fig.canvas.start_event_loop(0.0001)\r\n\t\t\t\r\n\t\t\t#This throws an error and breaks asyncio if you close the window before pausing\r\n\t\t\tself.fig.canvas.start_event_loop(0.001)\r\n\t\t\r\n\t\t\t#This works\r\n\t\t\t#self.fig.canvas.flush_events()\r\n\t\r\n\tdef stop(self, *args):\r\n\t\tself.running = False\r\n\t\tself.runButton['text'] = 'Run'\r\n\t\tself.runButton['command'] = self.start\r\n\t\r\n\tdef terminate(self, evt=False):\r\n\t\tself.running = False\r\n\t\tself.runButton['text'] = 'New Model'\r\n\t\tself.runButton['command'] = self.launchVisual\r\n\t\t\r\n\tdef launchVisual(self):\r\n\t\tmatplotlib.use('TkAgg')\r\n\t\tself.fig, self.axes = plt.subplots()\r\n\t\tself.fig.canvas.mpl_connect('close_event', self.terminate)\r\n\t\t\r\n\t\t#Keyboard input\r\n\t\tdef pause(event):\r\n\t\t\tif event.key==' ' and event.canvas is self.fig.canvas:\r\n\t\t\t\tif self.running: self.stop()\r\n\t\t\t\telse: self.start()\r\n\t\tself.fig.canvas.mpl_connect('key_press_event', pause)\r\n\t\t\r\n\t\tself.data = []\r\n\t\tself.line, = self.axes.plot(self.data, color='#330099')\r\n\t\t\r\n\t\tself.fig.canvas.draw_idle()\r\n\t\tplt.show(block=False)\r\n\t\t\r\n\t\tself.start()\r\n\r\nviz = Visual()\r\nviz.parent.mainloop()\r\n```","author":{"url":"https://github.com/charwick","@type":"Person","name":"charwick"},"datePublished":"2021-04-11T19:15:10.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/19940/matplotlib/issues/19940"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:058995e3-c7e6-858d-453a-c8baabfc41a9
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id82EA:2442E4:20DFB:2C5E7:6A51C914
html-safe-nonce73ee9478ba25dc132fb6761a830a6fd2718d934d2eb1a4e036dc243323cdcef4
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MkVBOjI0NDJFNDoyMERGQjoyQzVFNzo2QTUxQzkxNCIsInZpc2l0b3JfaWQiOiI4OTE0MTE0MTIxMDgwODgzNDc2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmacaf4eaf787f7d287aa7d1f35541c12e42aec993dc22320eb687803d1602b13b0b
hovercard-subject-tagissue:855385435
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/19940/issue_layout
twitter:imagehttps://opengraph.githubassets.com/c210624fcff83359badf00a2c81125e748c10060e25b7c83780434340d6811fc/matplotlib/matplotlib/issues/19940
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/c210624fcff83359badf00a2c81125e748c10060e25b7c83780434340d6811fc/matplotlib/matplotlib/issues/19940
og:image:altI have some code that continuously updates an MPL plot, and used fig.canvas.start_event_loop(0.0001) to listen for keyboard input. As of MPL 3.4, this code is broken in two ways: Commit c53570d con...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamecharwick
hostnamegithub.com
expected-hostnamegithub.com
Noneb9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb
turbo-cache-controlno-preview
go-importgithub.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git
octolytics-dimension-user_id215947
octolytics-dimension-user_loginmatplotlib
octolytics-dimension-repository_id1385122
octolytics-dimension-repository_nwomatplotlib/matplotlib
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1385122
octolytics-dimension-repository_network_root_nwomatplotlib/matplotlib
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release7aed05249554b889eb33d002851a973eebcc7e91
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/matplotlib/matplotlib/issues/19940#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fissues%2F19940
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fissues%2F19940
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=matplotlib%2Fmatplotlib
Reloadhttps://github.com/matplotlib/matplotlib/issues/19940
Reloadhttps://github.com/matplotlib/matplotlib/issues/19940
Reloadhttps://github.com/matplotlib/matplotlib/issues/19940
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/19940
matplotlib https://github.com/matplotlib
matplotlibhttps://github.com/matplotlib/matplotlib
Please reload this pagehttps://github.com/matplotlib/matplotlib/issues/19940
Notifications https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Fork 8.4k https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Star 23k https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Code https://github.com/matplotlib/matplotlib
Issues 1.1k https://github.com/matplotlib/matplotlib/issues
Pull requests 409 https://github.com/matplotlib/matplotlib/pulls
Actions https://github.com/matplotlib/matplotlib/actions
Projects https://github.com/matplotlib/matplotlib/projects
Wiki https://github.com/matplotlib/matplotlib/wiki
Security and quality 0 https://github.com/matplotlib/matplotlib/security
Insights https://github.com/matplotlib/matplotlib/pulse
Code https://github.com/matplotlib/matplotlib
Issues https://github.com/matplotlib/matplotlib/issues
Pull requests https://github.com/matplotlib/matplotlib/pulls
Actions https://github.com/matplotlib/matplotlib/actions
Projects https://github.com/matplotlib/matplotlib/projects
Wiki https://github.com/matplotlib/matplotlib/wiki
Security and quality https://github.com/matplotlib/matplotlib/security
Insights https://github.com/matplotlib/matplotlib/pulse
#19959https://github.com/matplotlib/matplotlib/pull/19959
Tkagg event loop throws error on window closehttps://github.com/matplotlib/matplotlib/issues/19940#top
#19959https://github.com/matplotlib/matplotlib/pull/19959
GUI: tkhttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22GUI%3A%20tk%22
v3.4.2https://github.com/matplotlib/matplotlib/milestone/63
https://github.com/charwick
charwickhttps://github.com/charwick
on Apr 11, 2021https://github.com/matplotlib/matplotlib/issues/19940#issue-855385435
Commit c53570dhttps://github.com/matplotlib/matplotlib/commit/c53570db3e602d2855813fa76a971ae3b62d361a
Commit 630e806https://github.com/matplotlib/matplotlib/commit/630e806ef7dfd0520490eeb85d2c866d8f8dca94
#2https://github.com/matplotlib/matplotlib/pull/2
@richardsheridanhttps://github.com/richardsheridan
GUI: tkhttps://github.com/matplotlib/matplotlib/issues?q=state%3Aopen%20label%3A%22GUI%3A%20tk%22
v3.4.2https://github.com/matplotlib/matplotlib/milestone/63
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.