{"action":"created","issue":{"url":"https://api.github.com/repos/qgis/QGIS/issues/3004","repository_url":"https://api.github.com/repos/qgis/QGIS","labels_url":"https://api.github.com/repos/qgis/QGIS/issues/3004/labels{/name}","comments_url":"https://api.github.com/repos/qgis/QGIS/issues/3004/comments","events_url":"https://api.github.com/repos/qgis/QGIS/issues/3004/events","html_url":"https://github.com/qgis/QGIS/pull/3004","id":148666227,"number":3004,"title":"Prototype: Task manager","user":{"login":"nyalldawson","id":1829991,"avatar_url":"https://avatars.githubusercontent.com/u/1829991?v=3","gravatar_id":"","url":"https://api.github.com/users/nyalldawson","html_url":"https://github.com/nyalldawson","followers_url":"https://api.github.com/users/nyalldawson/followers","following_url":"https://api.github.com/users/nyalldawson/following{/other_user}","gists_url":"https://api.github.com/users/nyalldawson/gists{/gist_id}","starred_url":"https://api.github.com/users/nyalldawson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nyalldawson/subscriptions","organizations_url":"https://api.github.com/users/nyalldawson/orgs","repos_url":"https://api.github.com/users/nyalldawson/repos","events_url":"https://api.github.com/users/nyalldawson/events{/privacy}","received_events_url":"https://api.github.com/users/nyalldawson/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/qgis/QGIS/labels/Prototype","name":"Prototype","color":"fad8c7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":38,"created_at":"2016-04-15T13:49:48Z","updated_at":"2016-05-28T09:05:51Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/qgis/QGIS/pulls/3004","html_url":"https://github.com/qgis/QGIS/pull/3004","diff_url":"https://github.com/qgis/QGIS/pull/3004.diff","patch_url":"https://github.com/qgis/QGIS/pull/3004.patch"},"body":"\r\nPrototype work in implementing a task manager for QGIS, with easy handling of submitting tasks to be run in the background and exposing their status to users.\r\n\r\nAdds new classes:\r\n- QgsTask. An interface for long-running background tasks. Tasks must implement the run() method to do their processing, and periodically test for `isCancelled()` to gracefully abort.\r\n- QgsTaskManager. Handles groups of tasks - also available as a global instance for tracking application wide tasks. Adding a task to a manager will cause the manager to handle launching the run() method in a separate thread.\r\n- QgsTaskManagerWidget. A list view for showing active tasks and their progress, and for cancelling them\r\n\r\nA new dock widget has been added with a task manager widget showing global tasks.\r\n\r\nYou can test with the following code:\r\n\r\n```\r\nfrom time import sleep\r\nclass TestTask( QgsTask ):\r\n        \r\n    def __init__(self, desc, time ):\r\n        QgsTask.__init__(self, desc )\r\n        self.time= time\r\n            \r\n    def run(self):\r\n        wait_time = self.time / 100.0\r\n        for i in range(101):\r\n            sleep(wait_time)\r\n            self.setProgress(i)\r\n            if self.isCancelled():\r\n                self.stopped()\r\n                return \r\n        self.completed()\r\n        \r\nfor time in range(10, 14):\r\n    task = TestTask('wait {}'.format( time ), time ) \r\n    QgsTaskManager.instance().addTask( task )\r\n\r\n```\r\n\r\nNote that I get crashes with this. My suspicion is that it's due to some oddness in SIP, but it's quite possible there's bugs in the code too!\r\n\r\n@wonder-sk Would appreciate you taking a look at this version!"},"comment":{"url":"https://api.github.com/repos/qgis/QGIS/issues/comments/222298520","html_url":"https://github.com/qgis/QGIS/pull/3004#issuecomment-222298520","issue_url":"https://api.github.com/repos/qgis/QGIS/issues/3004","id":222298520,"user":{"login":"mbernasocchi","id":233663,"avatar_url":"https://avatars.githubusercontent.com/u/233663?v=3","gravatar_id":"","url":"https://api.github.com/users/mbernasocchi","html_url":"https://github.com/mbernasocchi","followers_url":"https://api.github.com/users/mbernasocchi/followers","following_url":"https://api.github.com/users/mbernasocchi/following{/other_user}","gists_url":"https://api.github.com/users/mbernasocchi/gists{/gist_id}","starred_url":"https://api.github.com/users/mbernasocchi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbernasocchi/subscriptions","organizations_url":"https://api.github.com/users/mbernasocchi/orgs","repos_url":"https://api.github.com/users/mbernasocchi/repos","events_url":"https://api.github.com/users/mbernasocchi/events{/privacy}","received_events_url":"https://api.github.com/users/mbernasocchi/received_events","type":"User","site_admin":false},"created_at":"2016-05-28T09:05:51Z","updated_at":"2016-05-28T09:05:51Z","body":"I had implemented a [class](https://github.com/mbernasocchi/pyqtExperiments/blob/master/qgis_thread_example.py) (/set of classes) dealing with the same problem for plugins, and ended up using a similar approach. having this directly in core would be great.\r\n\r\nThe implementation looks really good to me. The only point I'm not super convinced is the naming of QgsTask.fromFunction. but also I've no better idea :/"}}
{"actor":{"display_login":"mbernasocchi"}}