{"action":"created","issue":{"url":"https://api.github.com/repos/bokeh/bokeh/issues/988","labels_url":"https://api.github.com/repos/bokeh/bokeh/issues/988/labels{/name}","comments_url":"https://api.github.com/repos/bokeh/bokeh/issues/988/comments","events_url":"https://api.github.com/repos/bokeh/bokeh/issues/988/events","html_url":"https://github.com/bokeh/bokeh/issues/988","id":40009808,"number":988,"title":"server event loop methodology","user":{"login":"hhuuggoo","id":249407,"avatar_url":"https://avatars.githubusercontent.com/u/249407?v=3","gravatar_id":"","url":"https://api.github.com/users/hhuuggoo","html_url":"https://github.com/hhuuggoo","followers_url":"https://api.github.com/users/hhuuggoo/followers","following_url":"https://api.github.com/users/hhuuggoo/following{/other_user}","gists_url":"https://api.github.com/users/hhuuggoo/gists{/gist_id}","starred_url":"https://api.github.com/users/hhuuggoo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hhuuggoo/subscriptions","organizations_url":"https://api.github.com/users/hhuuggoo/orgs","repos_url":"https://api.github.com/users/hhuuggoo/repos","events_url":"https://api.github.com/users/hhuuggoo/events{/privacy}","received_events_url":"https://api.github.com/users/hhuuggoo/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/bokeh/bokeh/labels/tag:server","name":"tag:server","color":"D0CBB8"},{"url":"https://api.github.com/repos/bokeh/bokeh/labels/type:%20discussion","name":"type: discussion","color":"2659A0"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2014-08-11T23:03:23Z","updated_at":"2015-07-10T18:44:27Z","closed_at":"2015-07-10T18:44:27Z","body":"This is my mental model of how the server event loop should work.  During an update on the server, this is what happens https://github.com/ContinuumIO/bokeh/blob/master/bokeh/server/views/backbone.py#L162\r\n- document is loaded from redis\r\n  - raw json is naively turned into PlotObjects (no references are resolved, no events are used)\r\n  - second pass through the object chain resolves all the references to other objects\r\n- new json is loaded from the web request into an existing backbone object\r\n- this update triggers events on changed properties\r\n- changed objects are pushed out over websockets\r\n\r\nThe important thing, is that we don't want to process events until all objects are created (or else you can't really bind to other objects)  We currently have 2 constructs for doing this,\r\n\r\n-  there is a _block_callbacks flag on a PlotObject which will tell plot objects to not execute events on changes, rather store them to be executed later. This was the original mechanism that used to induce this functionality.\r\n-  In addition during the 2 pass object initialization, it looks like now a second mechanism for doing this has appeared, In https://github.com/ContinuumIO/bokeh/blob/master/bokeh/document.py#L230, if an object is new (not loaded yet)  we don't setup any events, but instead we setup events during the finalize loop.  If an object is already existing, then we allow events to be triggered.\r\n\r\nI think the second (newer) mechanism that @mattpap  wrote (I think?) is better than the original.  I would advocate removing all concepts of _block_callbacks, and callback_queues, I think they are quite complicated and un-necessary.  And definitely having 2 constructs in there is redundant I believe.\r\n\r\nThen I think the logic is rather clear\r\n\r\n- load json from redis\r\n- Turn json into naive backbone objects\r\n- resolve references\r\n- setup events\r\n\r\nload new json from http request\r\n\r\n- update models\r\n\r\nOne concept we would have to preserve when eliminating the first approach is to make sure that the client can specify whether or not they want to trigger events or not during the update.  This is because in the python client is capable of processing events, so we can assume that all necessary events/changes have already occured on the client side and the server does not need to do anything.\r\n\r\ncc @mattpap @bryevdv @pzwang @kdodia "},"comment":{"url":"https://api.github.com/repos/bokeh/bokeh/issues/comments/120491447","html_url":"https://github.com/bokeh/bokeh/issues/988#issuecomment-120491447","issue_url":"https://api.github.com/repos/bokeh/bokeh/issues/988","id":120491447,"user":{"login":"birdsarah","id":1796208,"avatar_url":"https://avatars.githubusercontent.com/u/1796208?v=3","gravatar_id":"","url":"https://api.github.com/users/birdsarah","html_url":"https://github.com/birdsarah","followers_url":"https://api.github.com/users/birdsarah/followers","following_url":"https://api.github.com/users/birdsarah/following{/other_user}","gists_url":"https://api.github.com/users/birdsarah/gists{/gist_id}","starred_url":"https://api.github.com/users/birdsarah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/birdsarah/subscriptions","organizations_url":"https://api.github.com/users/birdsarah/orgs","repos_url":"https://api.github.com/users/birdsarah/repos","events_url":"https://api.github.com/users/birdsarah/events{/privacy}","received_events_url":"https://api.github.com/users/birdsarah/received_events","type":"User","site_admin":false},"created_at":"2015-07-10T18:44:27Z","updated_at":"2015-07-10T18:44:27Z","body":"Discussion is now more than 3 months old. Can re-open if renewed interest."}}