{"action":"created","issue":{"url":"https://api.github.com/repos/Noctem/Monocle/issues/357","repository_url":"https://api.github.com/repos/Noctem/Monocle","labels_url":"https://api.github.com/repos/Noctem/Monocle/issues/357/labels{/name}","comments_url":"https://api.github.com/repos/Noctem/Monocle/issues/357/comments","events_url":"https://api.github.com/repos/Noctem/Monocle/issues/357/events","html_url":"https://github.com/Noctem/Monocle/issues/357","id":250520877,"number":357,"title":"sqlite3.ProgrammingError","user":{"login":"almico","id":15247405,"avatar_url":"https://avatars2.githubusercontent.com/u/15247405?v=4","gravatar_id":"","url":"https://api.github.com/users/almico","html_url":"https://github.com/almico","followers_url":"https://api.github.com/users/almico/followers","following_url":"https://api.github.com/users/almico/following{/other_user}","gists_url":"https://api.github.com/users/almico/gists{/gist_id}","starred_url":"https://api.github.com/users/almico/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/almico/subscriptions","organizations_url":"https://api.github.com/users/almico/orgs","repos_url":"https://api.github.com/users/almico/repos","events_url":"https://api.github.com/users/almico/events{/privacy}","received_events_url":"https://api.github.com/users/almico/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-08-16T06:10:56Z","updated_at":"2017-08-17T18:47:41Z","closed_at":null,"body":"I looked at scan.log from scan.py (using the latest available Monocle source code) and found multiple errors like this.\r\nThis is one of them:\r\n```\r\n[2017-08-15 20:55:36][   ERROR][notifier] An exception occurred while trying to estimate remaining time.\r\nTraceback (most recent call last):\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/engine/base.py\", line 721, in _commit_impl\r\n    self.engine.dialect.do_commit(self.connection)\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/engine/default.py\", line 443, in do_commit\r\n    dbapi_connection.commit()\r\nsqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 139928004450048 and this is thread id 139931380840256\r\n\r\nThe above exception was the direct cause of the following exception:\r\n\r\nTraceback (most recent call last):\r\n  File \"/root/pogo/Monocle/monocle/db.py\", line 328, in session_scope\r\n    session.commit()\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/orm/session.py\", line 906, in commit\r\n    self.transaction.commit()\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/orm/session.py\", line 465, in commit\r\n    t[1].commit()\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/engine/base.py\", line 1632, in commit\r\n    self._do_commit()\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/engine/base.py\", line 1663, in _do_commit\r\n    self.connection._commit_impl()\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/engine/base.py\", line 723, in _commit_impl\r\n    self._handle_dbapi_exception(e, None, None, None, None)\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/engine/base.py\", line 1402, in _handle_dbapi_exception\r\n    exc_info\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/util/compat.py\", line 203, in raise_from_cause\r\n    reraise(type(exception), exception, tb=exc_tb, cause=cause)\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/util/compat.py\", line 186, in reraise\r\n    raise value.with_traceback(tb)\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/engine/base.py\", line 721, in _commit_impl\r\n    self.engine.dialect.do_commit(self.connection)\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/engine/default.py\", line 443, in do_commit\r\n    dbapi_connection.commit()\r\nsqlalchemy.exc.ProgrammingError: (sqlite3.ProgrammingError) SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 139928004450\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/engine/base.py\", line 701, in _rollback_impl\r\n    self.engine.dialect.do_rollback(self.connection)\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/engine/default.py\", line 440, in do_rollback\r\n    dbapi_connection.rollback()\r\nsqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 139928004450048 and this is thread id 139931380840256\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/engine/base.py\", line 701, in _rollback_impl\r\n    self.engine.dialect.do_rollback(self.connection)\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/engine/default.py\", line 440, in do_rollback\r\n    dbapi_connection.rollback()\r\nsqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 139928004450048 and this is thread id 139931380840256\r\n\r\nThe above exception was the direct cause of the following exception:\r\n\r\nTraceback (most recent call last):\r\n  File \"/root/pogo/Monocle/monocle/notification.py\", line 724, in notify\r\n    tth = await run_threaded(estimate_remaining_time, session, pokemon['spawn_id'], seen)\r\n  File \"/usr/lib64/python3.6/contextlib.py\", line 88, in __exit__\r\n    next(self.gen)\r\n  File \"/root/pogo/Monocle/monocle/db.py\", line 330, in session_scope\r\n    session.rollback()\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/orm/session.py\", line 870, in rollback\r\n    self.transaction.rollback()\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/orm/session.py\", line 518, in rollback\r\n    util.reraise(*rollback_err)\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/util/compat.py\", line 187, in reraise\r\n    raise value\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/orm/session.py\", line 490, in rollback\r\n    transaction._rollback_impl()\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/orm/session.py\", line 527, in _rollback_impl\r\n    t[1].rollback()\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/engine/base.py\", line 1621, in rollback\r\n    self._do_rollback()\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/engine/base.py\", line 1659, in _do_rollback\r\n    self.connection._rollback_impl()\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/engine/base.py\", line 703, in _rollback_impl\r\n    self._handle_dbapi_exception(e, None, None, None, None)\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/engine/base.py\", line 1395, in _handle_dbapi_exception\r\n    self._autorollback()\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py\", line 76, in __exit__\r\n    compat.reraise(type_, value, traceback)\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/util/compat.py\", line 187, in reraise\r\n    raise value\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/engine/base.py\", line 1395, in _handle_dbapi_exception\r\n    self._autorollback()\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/engine/base.py\", line 824, in _autorollback\r\n    self._root._rollback_impl()\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/engine/base.py\", line 703, in _rollback_impl\r\n    self._handle_dbapi_exception(e, None, None, None, None)\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/engine/base.py\", line 1323, in _handle_dbapi_exception\r\n    exc_info\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/util/compat.py\", line 203, in raise_from_cause\r\n    reraise(type(exception), exception, tb=exc_tb, cause=cause)\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/util/compat.py\", line 186, in reraise\r\n    raise value.with_traceback(tb)\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/engine/base.py\", line 701, in _rollback_impl\r\n    self.engine.dialect.do_rollback(self.connection)\r\n  File \"/usr/lib/python3.6/site-packages/sqlalchemy/engine/default.py\", line 440, in do_rollback\r\n    dbapi_connection.rollback()\r\nsqlalchemy.exc.ProgrammingError: (sqlite3.ProgrammingError) SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 139928004450048 and this is thread id 139931380840256\r\n```"},"comment":{"url":"https://api.github.com/repos/Noctem/Monocle/issues/comments/323160718","html_url":"https://github.com/Noctem/Monocle/issues/357#issuecomment-323160718","issue_url":"https://api.github.com/repos/Noctem/Monocle/issues/357","id":323160718,"user":{"login":"mewio","id":26984568,"avatar_url":"https://avatars3.githubusercontent.com/u/26984568?v=4","gravatar_id":"","url":"https://api.github.com/users/mewio","html_url":"https://github.com/mewio","followers_url":"https://api.github.com/users/mewio/followers","following_url":"https://api.github.com/users/mewio/following{/other_user}","gists_url":"https://api.github.com/users/mewio/gists{/gist_id}","starred_url":"https://api.github.com/users/mewio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mewio/subscriptions","organizations_url":"https://api.github.com/users/mewio/orgs","repos_url":"https://api.github.com/users/mewio/repos","events_url":"https://api.github.com/users/mewio/events{/privacy}","received_events_url":"https://api.github.com/users/mewio/received_events","type":"User","site_admin":false},"created_at":"2017-08-17T18:47:41Z","updated_at":"2017-08-17T18:47:41Z","body":"It is caused by incorrect use of database API objects in notification.py. My notification system rewrite (#241) will fix this problem, but if you're in a hurry for a short-term fix, you can apply this patch:\r\n\r\n    diff --git a/monocle/notification.py b/monocle/notification.py\r\n    index 754ccf4..3a2ba95 100755\r\n    --- a/monocle/notification.py\r\n    +++ b/monocle/notification.py\r\n    @@ -720,8 +720,10 @@ class Notifier:\r\n                 seen = pokemon['seen'] % 3600\r\n                 cache_handle = self.cache.store.add(pokemon['encounter_id'])\r\n                 try:\r\n    -                with session_scope() as session:\r\n    -                    tth = await run_threaded(estimate_remaining_time, session, pokemon['spawn_id'], seen)\r\n    +                def xxx_estimate_remaining_time_with_session():\r\n    +                    with session_scope() as session:\r\n    +                        return estimate_remaining_time(session, pokemon['spawn_id'], seen)\r\n    +                tth = await run_threaded(xxx_estimate_remaining_time_with_session)\r\n                 except Exception:\r\n                     self.log.exception('An exception occurred while trying to estimate remaining time.')\r\n                     now_epoch = time()\r\n"}}
{"actor":{"display_login":"mewio"}}