{"action":"created","issue":{"url":"https://api.github.com/repos/dronekit/dronekit-python/issues/864","repository_url":"https://api.github.com/repos/dronekit/dronekit-python","labels_url":"https://api.github.com/repos/dronekit/dronekit-python/issues/864/labels{/name}","comments_url":"https://api.github.com/repos/dronekit/dronekit-python/issues/864/comments","events_url":"https://api.github.com/repos/dronekit/dronekit-python/issues/864/events","html_url":"https://github.com/dronekit/dronekit-python/pull/864","id":374727383,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI2MzQ5NDA4","number":864,"title":"mavlink.py: efficient I/O waiting with select()","user":{"login":"pietrodn","id":5058646,"node_id":"MDQ6VXNlcjUwNTg2NDY=","avatar_url":"https://avatars3.githubusercontent.com/u/5058646?v=4","gravatar_id":"","url":"https://api.github.com/users/pietrodn","html_url":"https://github.com/pietrodn","followers_url":"https://api.github.com/users/pietrodn/followers","following_url":"https://api.github.com/users/pietrodn/following{/other_user}","gists_url":"https://api.github.com/users/pietrodn/gists{/gist_id}","starred_url":"https://api.github.com/users/pietrodn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pietrodn/subscriptions","organizations_url":"https://api.github.com/users/pietrodn/orgs","repos_url":"https://api.github.com/users/pietrodn/repos","events_url":"https://api.github.com/users/pietrodn/events{/privacy}","received_events_url":"https://api.github.com/users/pietrodn/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-10-28T07:47:11Z","updated_at":"2018-10-29T11:04:39Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/dronekit/dronekit-python/pulls/864","html_url":"https://github.com/dronekit/dronekit-python/pull/864","diff_url":"https://github.com/dronekit/dronekit-python/pull/864.diff","patch_url":"https://github.com/dronekit/dronekit-python/pull/864.patch"},"body":"pymavlink uses non-blocking [sockets](https://github.com/ArduPilot/pymavlink/blob/master/mavutil.py#L926) and [serial ports](https://github.com/ArduPilot/pymavlink/blob/master/mavutil.py#L824): polling for data in a while loop with a `sleep(0.05)` is inefficient and leads to increased latency for incoming MAVLink messages (issue #863).\r\n\r\nBut, if the `sleep` call is blindly removed, then the CPU usage rises to 100% (busy-looping)!\r\n\r\nThe [`select()`](https://docs.python.org/3/library/select.html#select.select) system call, [exposed in the pymavlink API](https://github.com/ArduPilot/pymavlink/blob/master/mavutil.py#L209), puts the `mavlink_thread_in` thread to sleep for just the right amount of time and wakes it up when fresh data is ready to be processed.\r\n\r\nIf `select()` is used, the returned message may never be `None`, so the loop listeners would never get called. This is also fixed by ensuring that the loop listeners are called at least every 0.5 s."},"comment":{"url":"https://api.github.com/repos/dronekit/dronekit-python/issues/comments/433870666","html_url":"https://github.com/dronekit/dronekit-python/pull/864#issuecomment-433870666","issue_url":"https://api.github.com/repos/dronekit/dronekit-python/issues/864","id":433870666,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMzg3MDY2Ng==","user":{"login":"pietrodn","id":5058646,"node_id":"MDQ6VXNlcjUwNTg2NDY=","avatar_url":"https://avatars3.githubusercontent.com/u/5058646?v=4","gravatar_id":"","url":"https://api.github.com/users/pietrodn","html_url":"https://github.com/pietrodn","followers_url":"https://api.github.com/users/pietrodn/followers","following_url":"https://api.github.com/users/pietrodn/following{/other_user}","gists_url":"https://api.github.com/users/pietrodn/gists{/gist_id}","starred_url":"https://api.github.com/users/pietrodn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pietrodn/subscriptions","organizations_url":"https://api.github.com/users/pietrodn/orgs","repos_url":"https://api.github.com/users/pietrodn/repos","events_url":"https://api.github.com/users/pietrodn/events{/privacy}","received_events_url":"https://api.github.com/users/pietrodn/received_events","type":"User","site_admin":false},"created_at":"2018-10-29T11:04:39Z","updated_at":"2018-10-29T11:04:39Z","author_association":"CONTRIBUTOR","body":"Thanks! Just squashed the commits."}}
{"actor":{"display_login":"pietrodn"}}