{"action":"created","issue":{"url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/issues/387","repository_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero","labels_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/issues/387/labels{/name}","comments_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/issues/387/comments","events_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/issues/387/events","html_url":"https://github.com/RPi-Distro/python-gpiozero/issues/387","id":163161283,"number":387,"title":"[performance] Button - huge CPU hog","user":{"login":"elegantandrogyne","id":7027314,"avatar_url":"https://avatars.githubusercontent.com/u/7027314?v=3","gravatar_id":"","url":"https://api.github.com/users/elegantandrogyne","html_url":"https://github.com/elegantandrogyne","followers_url":"https://api.github.com/users/elegantandrogyne/followers","following_url":"https://api.github.com/users/elegantandrogyne/following{/other_user}","gists_url":"https://api.github.com/users/elegantandrogyne/gists{/gist_id}","starred_url":"https://api.github.com/users/elegantandrogyne/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elegantandrogyne/subscriptions","organizations_url":"https://api.github.com/users/elegantandrogyne/orgs","repos_url":"https://api.github.com/users/elegantandrogyne/repos","events_url":"https://api.github.com/users/elegantandrogyne/events{/privacy}","received_events_url":"https://api.github.com/users/elegantandrogyne/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-06-30T13:08:56Z","updated_at":"2016-08-14T22:24:20Z","closed_at":"2016-06-30T14:38:15Z","body":"Whenever I instantiate the Button class, I get ca. 35% CPU load per instance:\r\n\r\n1. run \"sudo python3\" in one console and open \"top\" or \"htop\" in another one for monitoring\r\n2. find the python3 process in the top list\r\n3. enter in python interactive mode:\r\n\r\n`import gpiozero`\r\n`button1 = gpiozero.Button(4)`\r\n\r\nEFFECT: +30...35% CPU load by python3 after instantiation of Button\r\nSHOULD BE: CPU load doesn't rise drastically\r\n\r\nNow try creating some more Button instances for different GPIO pins:\r\n\r\n`button2 = gpiozero.Button(24)`\r\n\r\nEFFECT: the CPU load rises proportionally, causing the Raspberry to run out of resources if too many instances are created\r\n\r\nTry to get rid of the instances:\r\n\r\n`button1 = None`\r\n`button2 = None`\r\n\r\nEFFECT: CPU load doesn't drop\r\nSHOULD BE: instances are deleted and the load drops\r\n\r\nExit the interpreter:\r\n\r\n`exit()`\r\n\r\nEFFECT: the CPU load finally comes back to normal.\r\n\r\nTested on the old RPi B rev 2 and B+, Raspbian stretch, Python 3.5.2"},"comment":{"url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/issues/comments/239701567","html_url":"https://github.com/RPi-Distro/python-gpiozero/issues/387#issuecomment-239701567","issue_url":"https://api.github.com/repos/RPi-Distro/python-gpiozero/issues/387","id":239701567,"user":{"login":"waveform80","id":1076190,"avatar_url":"https://avatars.githubusercontent.com/u/1076190?v=3","gravatar_id":"","url":"https://api.github.com/users/waveform80","html_url":"https://github.com/waveform80","followers_url":"https://api.github.com/users/waveform80/followers","following_url":"https://api.github.com/users/waveform80/following{/other_user}","gists_url":"https://api.github.com/users/waveform80/gists{/gist_id}","starred_url":"https://api.github.com/users/waveform80/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/waveform80/subscriptions","organizations_url":"https://api.github.com/users/waveform80/orgs","repos_url":"https://api.github.com/users/waveform80/repos","events_url":"https://api.github.com/users/waveform80/events{/privacy}","received_events_url":"https://api.github.com/users/waveform80/received_events","type":"User","site_admin":false},"created_at":"2016-08-14T22:24:20Z","updated_at":"2016-08-14T22:24:20Z","body":"Yeah, `NativePin` is horribly slow when it comes to polling at the moment. I should find some time to speed it up by using epoll instead of Python threads - however, this isn't a major priority given it's literally just a fallback implementation at the moment (it becomes a little more interesting with the pypy use-case, but I suspect pigpio ought to work happily with pypy given it's just sending stuff over a socket - or if it doesn't, it should be trivial to make it work).\r\n\r\nAnyway, that's the reason this was horrifically slow. As for the warning, if anyone wants to implement it the best place is probably in NativePin's constructor (`__new__` if I recall) - just throw a warning there (\"Using slow NativePin\") and Python's default warning filter should ensure it doesn't spam the console."}}
{"actor":{"display_login":"waveform80"}}