{"action":"closed","issue":{"url":"https://api.github.com/repos/pybind/pybind11/issues/404","repository_url":"https://api.github.com/repos/pybind/pybind11","labels_url":"https://api.github.com/repos/pybind/pybind11/issues/404/labels{/name}","comments_url":"https://api.github.com/repos/pybind/pybind11/issues/404/comments","events_url":"https://api.github.com/repos/pybind/pybind11/issues/404/events","html_url":"https://github.com/pybind/pybind11/issues/404","id":176137209,"number":404,"title":"py::print doesn't work while a PyErr is set","user":{"login":"jagerman","id":4459524,"avatar_url":"https://avatars.githubusercontent.com/u/4459524?v=3","gravatar_id":"","url":"https://api.github.com/users/jagerman","html_url":"https://github.com/jagerman","followers_url":"https://api.github.com/users/jagerman/followers","following_url":"https://api.github.com/users/jagerman/following{/other_user}","gists_url":"https://api.github.com/users/jagerman/gists{/gist_id}","starred_url":"https://api.github.com/users/jagerman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jagerman/subscriptions","organizations_url":"https://api.github.com/users/jagerman/orgs","repos_url":"https://api.github.com/users/jagerman/repos","events_url":"https://api.github.com/users/jagerman/events{/privacy}","received_events_url":"https://api.github.com/users/jagerman/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-09-09T23:35:21Z","updated_at":"2016-09-10T07:33:42Z","closed_at":"2016-09-10T07:33:42Z","body":"@dean0x7d \r\n`py::print` fails when a python error is currently set; I eventually tracked it down to these lines in `simple_collector`/`unpacking_collector`:\r\n\r\n```C++\r\n        auto result = object(PyObject_CallObject(ptr, m_args.ptr()), false);\r\n        if (!result)\r\n            throw error_already_set();\r\n```\r\nIf PyErr is currently set, the call fails, and py::print throws an exception.  This is particular a problem if py::print is used in a destructor because the destructor may well have been invoked as part of stack unwinding because of a previous throw error_already_set().\r\n\r\nI ran into this just now while updating PR #264, where exactly this happened: one of the tests was to test that an exception happened, but during the exception, `ConstructorStats::print_destroyed` is invoked, which now uses `py::print`.\r\n\r\nI put in [this workaround](https://github.com/jagerman/pybind11/commit/4d8b2d5fb0c387e62a81f2055e788fe231c6600b) to temporarily work around the issue, but I think something similar should be moved up into `py::print`."}}
{"actor":{"display_login":"wjakob"}}