{"action":"created","issue":{"url":"https://api.github.com/repos/r9y9/pylibfreenect2/issues/18","repository_url":"https://api.github.com/repos/r9y9/pylibfreenect2","labels_url":"https://api.github.com/repos/r9y9/pylibfreenect2/issues/18/labels{/name}","comments_url":"https://api.github.com/repos/r9y9/pylibfreenect2/issues/18/comments","events_url":"https://api.github.com/repos/r9y9/pylibfreenect2/issues/18/events","html_url":"https://github.com/r9y9/pylibfreenect2/issues/18","id":164151863,"number":18,"title":"Device gets closed when code gets out of the scope","user":{"login":"tianyangma","id":2067372,"avatar_url":"https://avatars.githubusercontent.com/u/2067372?v=3","gravatar_id":"","url":"https://api.github.com/users/tianyangma","html_url":"https://github.com/tianyangma","followers_url":"https://api.github.com/users/tianyangma/followers","following_url":"https://api.github.com/users/tianyangma/following{/other_user}","gists_url":"https://api.github.com/users/tianyangma/gists{/gist_id}","starred_url":"https://api.github.com/users/tianyangma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tianyangma/subscriptions","organizations_url":"https://api.github.com/users/tianyangma/orgs","repos_url":"https://api.github.com/users/tianyangma/repos","events_url":"https://api.github.com/users/tianyangma/events{/privacy}","received_events_url":"https://api.github.com/users/tianyangma/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-07-06T19:12:36Z","updated_at":"2016-07-07T03:21:36Z","closed_at":null,"body":"A sample code snippet is:\r\n\r\n```python\r\ndef open_device():\r\n    # Create a processing pipeline.\r\n    pipeline = OpenGLPacketPipeline()\r\n    \r\n    # Create a logger.\r\n    logger = createConsoleLogger(LoggerLevel.Debug)\r\n    setGlobalLogger(logger)\r\n                \r\n    # Discover Kinect device.\r\n    fn = Freenect2()\r\n    num_devices = fn.enumerateDevices()\r\n    if num_devices == 0:\r\n        print(\"No device connected!\")\r\n        sys.exit(1)\r\n    \r\n    serial = fn.getDeviceSerialNumber(0)\r\n                \r\n    # Connect to the device.\r\n    device = fn.openDevice(serial, pipeline=pipeline)\r\n                \r\n    # Register listeners.\r\n    listener = SyncMultiFrameListener(FrameType.Depth)\r\n    device.setIrAndDepthFrameListener(listener)\r\n    \r\n    return device, listener\r\n\r\ndevice, listener = open_device()\r\n\r\nwhile True:\r\n    cv2.waitKey(-1)\r\n```\r\n\r\nIn this case, the device gets closed when exiting the function call ```open_device()```."},"comment":{"url":"https://api.github.com/repos/r9y9/pylibfreenect2/issues/comments/230969116","html_url":"https://github.com/r9y9/pylibfreenect2/issues/18#issuecomment-230969116","issue_url":"https://api.github.com/repos/r9y9/pylibfreenect2/issues/18","id":230969116,"user":{"login":"r9y9","id":1220272,"avatar_url":"https://avatars.githubusercontent.com/u/1220272?v=3","gravatar_id":"","url":"https://api.github.com/users/r9y9","html_url":"https://github.com/r9y9","followers_url":"https://api.github.com/users/r9y9/followers","following_url":"https://api.github.com/users/r9y9/following{/other_user}","gists_url":"https://api.github.com/users/r9y9/gists{/gist_id}","starred_url":"https://api.github.com/users/r9y9/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/r9y9/subscriptions","organizations_url":"https://api.github.com/users/r9y9/orgs","repos_url":"https://api.github.com/users/r9y9/repos","events_url":"https://api.github.com/users/r9y9/events{/privacy}","received_events_url":"https://api.github.com/users/r9y9/received_events","type":"User","site_admin":false},"created_at":"2016-07-07T03:21:36Z","updated_at":"2016-07-07T03:21:36Z","body":"Yes, you should keep `fn` (instance of `Freenect2`) to keep your device open. This is because `Freenect2` is responsible to manage devices and `openDevice` just returns the raw pointer of allocated device object. In this case, `fn` will get deallocated after `open_device` and device get deallocated (i.e.closed) as well."}}
{"actor":{"display_login":"r9y9"}}