{"action":"opened","issue":{"url":"https://api.github.com/repos/quantopian/zipline/issues/1235","repository_url":"https://api.github.com/repos/quantopian/zipline","labels_url":"https://api.github.com/repos/quantopian/zipline/issues/1235/labels{/name}","comments_url":"https://api.github.com/repos/quantopian/zipline/issues/1235/comments","events_url":"https://api.github.com/repos/quantopian/zipline/issues/1235/events","html_url":"https://github.com/quantopian/zipline/issues/1235","id":156850525,"number":1235,"title":"Remove Cycles Between TradingAlgorithm and AlgorithmSimulator","user":{"login":"ssanderson","id":1588357,"avatar_url":"https://avatars.githubusercontent.com/u/1588357?v=3","gravatar_id":"","url":"https://api.github.com/users/ssanderson","html_url":"https://github.com/ssanderson","followers_url":"https://api.github.com/users/ssanderson/followers","following_url":"https://api.github.com/users/ssanderson/following{/other_user}","gists_url":"https://api.github.com/users/ssanderson/gists{/gist_id}","starred_url":"https://api.github.com/users/ssanderson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ssanderson/subscriptions","organizations_url":"https://api.github.com/users/ssanderson/orgs","repos_url":"https://api.github.com/users/ssanderson/repos","events_url":"https://api.github.com/users/ssanderson/events{/privacy}","received_events_url":"https://api.github.com/users/ssanderson/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/quantopian/zipline/labels/API%20Design","name":"API Design","color":"afffff"},{"url":"https://api.github.com/repos/quantopian/zipline/labels/Bug","name":"Bug","color":"fc2929"},{"url":"https://api.github.com/repos/quantopian/zipline/labels/Dev%20Experience","name":"Dev Experience","color":"362d6a"},{"url":"https://api.github.com/repos/quantopian/zipline/labels/Windows","name":"Windows","color":"207de5"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-05-25T21:06:43Z","updated_at":"2016-05-25T21:06:43Z","closed_at":null,"body":"AppVeyor builds mysteriously started failing on https://github.com/quantopian/zipline/pull/1230 trying to delete the adjustments db in a temporary directory.\r\n\r\nThe root of the issue, ultimately, is the fact that we create a cycle between TradingAlgorithm and AlgorithmSimulator, which prevents deterministic collection of any resources referenced by the Algorithm.\r\n\r\nI tried debugging this using the [objgraph](http://mg.pov.lt/objgraph/objgraph.html#module-objgraph) package, but was initially stymied because I was getting empty graphs when trying to find referrers to `SQLiteAdjustmentReader`.  Reading the source, I learned that most objgraph functions call `gc.collect` before building their graphs, which cleaned up the reader I was trying to debug.  The solution to this was to monkey-patch `gc.collect` when generating reference graphs.\r\n\r\nFor future reference, anyone trying to debug a nondeterministic gc collection issue with objgraph should use something like the following:\r\n\r\n```\r\n        import gc; import objgraph\r\n        gc.collect = lambda: 0\r\n        objgraph.show_backrefs(\r\n            objgraph.by_type('SQLiteAdjustmentReader'),\r\n            max_depth=5,\r\n            too_many=20,\r\n            filename='/home/ssanderson/backrefs.svg',\r\n        )\r\n```\r\n\r\nThe result of which is:\r\n\r\n![backrefs2](https://cloud.githubusercontent.com/assets/1588357/15556143/69576404-229a-11e6-894a-fdd277db7878.png)\r\n"}}
{"actor":{"display_login":"ssanderson"}}