{"action":"created","comment":{"url":"https://api.github.com/repos/ipython/ipython/pulls/comments/24347250","id":24347250,"diff_hunk":"@@ -63,6 +66,10 @@ def __init__(self, target_name='', data=None, **kwargs):\n     \n     def _publish_msg(self, msg_type, data=None, metadata=None, buffers=None, **keys):\n         \"\"\"Helper for sending a comm message on IOPub\"\"\"\n+        if threading.current_thread().name != 'MainThread' and IOLoop.initialized():\n+            # make sure we never send on a zmq socket outside the main IOLoop thread\n+            IOLoop.instance().add_callback(lambda : self._publish_msg(msg_type, data, metadata, buffers, **keys))","path":"IPython/kernel/comm/comm.py","position":27,"original_position":27,"commit_id":"f18f5551d80d83f5a6cfbcedb281bbe0b8e6cef7","original_commit_id":"f18f5551d80d83f5a6cfbcedb281bbe0b8e6cef7","user":{"login":"jdfreder","id":3292874,"avatar_url":"https://avatars.githubusercontent.com/u/3292874?v=3","gravatar_id":"","url":"https://api.github.com/users/jdfreder","html_url":"https://github.com/jdfreder","followers_url":"https://api.github.com/users/jdfreder/followers","following_url":"https://api.github.com/users/jdfreder/following{/other_user}","gists_url":"https://api.github.com/users/jdfreder/gists{/gist_id}","starred_url":"https://api.github.com/users/jdfreder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdfreder/subscriptions","organizations_url":"https://api.github.com/users/jdfreder/orgs","repos_url":"https://api.github.com/users/jdfreder/repos","events_url":"https://api.github.com/users/jdfreder/events{/privacy}","received_events_url":"https://api.github.com/users/jdfreder/received_events","type":"User","site_admin":false},"body":"@minrk is there a chance that the callback list will overflow if you are adding callbacks to it quickly?  In other words, does the IOLoop instance do something like this:\r\n\r\n```python\r\ndef tick(self):\r\n    callback = self.callbacks.pop()\r\n    callback()\r\n```\r\n\r\nor does it clear the whole buffer each iteration?\r\n\r\n```python\r\ndef tick(self):\r\n    while len(self.callbacks) > 0:\r\n        callback = self.callbacks.pop()\r\n        callback()\r\n```","created_at":"2015-02-09T17:35:18Z","updated_at":"2015-02-09T17:35:18Z","html_url":"https://github.com/ipython/ipython/pull/7706#discussion_r24347250","pull_request_url":"https://api.github.com/repos/ipython/ipython/pulls/7706","_links":{"self":{"href":"https://api.github.com/repos/ipython/ipython/pulls/comments/24347250"},"html":{"href":"https://github.com/ipython/ipython/pull/7706#discussion_r24347250"},"pull_request":{"href":"https://api.github.com/repos/ipython/ipython/pulls/7706"}}},"pull_request":{"url":"https://api.github.com/repos/ipython/ipython/pulls/7706","id":28850352,"html_url":"https://github.com/ipython/ipython/pull/7706","diff_url":"https://github.com/ipython/ipython/pull/7706.diff","patch_url":"https://github.com/ipython/ipython/pull/7706.patch","issue_url":"https://api.github.com/repos/ipython/ipython/issues/7706","number":7706,"state":"open","locked":false,"title":"make Comm publishing threadsafe","user":{"login":"minrk","id":151929,"avatar_url":"https://avatars.githubusercontent.com/u/151929?v=3","gravatar_id":"","url":"https://api.github.com/users/minrk","html_url":"https://github.com/minrk","followers_url":"https://api.github.com/users/minrk/followers","following_url":"https://api.github.com/users/minrk/following{/other_user}","gists_url":"https://api.github.com/users/minrk/gists{/gist_id}","starred_url":"https://api.github.com/users/minrk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/minrk/subscriptions","organizations_url":"https://api.github.com/users/minrk/orgs","repos_url":"https://api.github.com/users/minrk/repos","events_url":"https://api.github.com/users/minrk/events{/privacy}","received_events_url":"https://api.github.com/users/minrk/received_events","type":"User","site_admin":false},"body":"If a Comm tries to send a message from another thread, schedule it to be called ASAP in the main thread via IOLoop.add_callback.\n\nping @jdfreder","created_at":"2015-02-06T23:14:28Z","updated_at":"2015-02-09T17:35:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"379cd1542f2f8494fade379622aaed318d0816b7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ipython/ipython/pulls/7706/commits","review_comments_url":"https://api.github.com/repos/ipython/ipython/pulls/7706/comments","review_comment_url":"https://api.github.com/repos/ipython/ipython/pulls/comments/{number}","comments_url":"https://api.github.com/repos/ipython/ipython/issues/7706/comments","statuses_url":"https://api.github.com/repos/ipython/ipython/statuses/f18f5551d80d83f5a6cfbcedb281bbe0b8e6cef7","head":{"label":"minrk:thread-comm","ref":"thread-comm","sha":"f18f5551d80d83f5a6cfbcedb281bbe0b8e6cef7","user":{"login":"minrk","id":151929,"avatar_url":"https://avatars.githubusercontent.com/u/151929?v=3","gravatar_id":"","url":"https://api.github.com/users/minrk","html_url":"https://github.com/minrk","followers_url":"https://api.github.com/users/minrk/followers","following_url":"https://api.github.com/users/minrk/following{/other_user}","gists_url":"https://api.github.com/users/minrk/gists{/gist_id}","starred_url":"https://api.github.com/users/minrk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/minrk/subscriptions","organizations_url":"https://api.github.com/users/minrk/orgs","repos_url":"https://api.github.com/users/minrk/repos","events_url":"https://api.github.com/users/minrk/events{/privacy}","received_events_url":"https://api.github.com/users/minrk/received_events","type":"User","site_admin":false},"repo":{"id":659446,"name":"ipython","full_name":"minrk/ipython","owner":{"login":"minrk","id":151929,"avatar_url":"https://avatars.githubusercontent.com/u/151929?v=3","gravatar_id":"","url":"https://api.github.com/users/minrk","html_url":"https://github.com/minrk","followers_url":"https://api.github.com/users/minrk/followers","following_url":"https://api.github.com/users/minrk/following{/other_user}","gists_url":"https://api.github.com/users/minrk/gists{/gist_id}","starred_url":"https://api.github.com/users/minrk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/minrk/subscriptions","organizations_url":"https://api.github.com/users/minrk/orgs","repos_url":"https://api.github.com/users/minrk/repos","events_url":"https://api.github.com/users/minrk/events{/privacy}","received_events_url":"https://api.github.com/users/minrk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/minrk/ipython","description":"","fork":true,"url":"https://api.github.com/repos/minrk/ipython","forks_url":"https://api.github.com/repos/minrk/ipython/forks","keys_url":"https://api.github.com/repos/minrk/ipython/keys{/key_id}","collaborators_url":"https://api.github.com/repos/minrk/ipython/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/minrk/ipython/teams","hooks_url":"https://api.github.com/repos/minrk/ipython/hooks","issue_events_url":"https://api.github.com/repos/minrk/ipython/issues/events{/number}","events_url":"https://api.github.com/repos/minrk/ipython/events","assignees_url":"https://api.github.com/repos/minrk/ipython/assignees{/user}","branches_url":"https://api.github.com/repos/minrk/ipython/branches{/branch}","tags_url":"https://api.github.com/repos/minrk/ipython/tags","blobs_url":"https://api.github.com/repos/minrk/ipython/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/minrk/ipython/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/minrk/ipython/git/refs{/sha}","trees_url":"https://api.github.com/repos/minrk/ipython/git/trees{/sha}","statuses_url":"https://api.github.com/repos/minrk/ipython/statuses/{sha}","languages_url":"https://api.github.com/repos/minrk/ipython/languages","stargazers_url":"https://api.github.com/repos/minrk/ipython/stargazers","contributors_url":"https://api.github.com/repos/minrk/ipython/contributors","subscribers_url":"https://api.github.com/repos/minrk/ipython/subscribers","subscription_url":"https://api.github.com/repos/minrk/ipython/subscription","commits_url":"https://api.github.com/repos/minrk/ipython/commits{/sha}","git_commits_url":"https://api.github.com/repos/minrk/ipython/git/commits{/sha}","comments_url":"https://api.github.com/repos/minrk/ipython/comments{/number}","issue_comment_url":"https://api.github.com/repos/minrk/ipython/issues/comments/{number}","contents_url":"https://api.github.com/repos/minrk/ipython/contents/{+path}","compare_url":"https://api.github.com/repos/minrk/ipython/compare/{base}...{head}","merges_url":"https://api.github.com/repos/minrk/ipython/merges","archive_url":"https://api.github.com/repos/minrk/ipython/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/minrk/ipython/downloads","issues_url":"https://api.github.com/repos/minrk/ipython/issues{/number}","pulls_url":"https://api.github.com/repos/minrk/ipython/pulls{/number}","milestones_url":"https://api.github.com/repos/minrk/ipython/milestones{/number}","notifications_url":"https://api.github.com/repos/minrk/ipython/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/minrk/ipython/labels{/name}","releases_url":"https://api.github.com/repos/minrk/ipython/releases{/id}","created_at":"2010-05-10T18:37:01Z","updated_at":"2015-02-08T00:15:19Z","pushed_at":"2015-02-07T23:43:11Z","git_url":"git://github.com/minrk/ipython.git","ssh_url":"git@github.com:minrk/ipython.git","clone_url":"https://github.com/minrk/ipython.git","svn_url":"https://github.com/minrk/ipython","homepage":"","size":73616,"stargazers_count":17,"watchers_count":17,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":17,"default_branch":"master"}},"base":{"label":"ipython:master","ref":"master","sha":"88ac07de9a2e770f7faa317dbc5346d9a2aa0c60","user":{"login":"ipython","id":230453,"avatar_url":"https://avatars.githubusercontent.com/u/230453?v=3","gravatar_id":"","url":"https://api.github.com/users/ipython","html_url":"https://github.com/ipython","followers_url":"https://api.github.com/users/ipython/followers","following_url":"https://api.github.com/users/ipython/following{/other_user}","gists_url":"https://api.github.com/users/ipython/gists{/gist_id}","starred_url":"https://api.github.com/users/ipython/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ipython/subscriptions","organizations_url":"https://api.github.com/users/ipython/orgs","repos_url":"https://api.github.com/users/ipython/repos","events_url":"https://api.github.com/users/ipython/events{/privacy}","received_events_url":"https://api.github.com/users/ipython/received_events","type":"Organization","site_admin":false},"repo":{"id":658518,"name":"ipython","full_name":"ipython/ipython","owner":{"login":"ipython","id":230453,"avatar_url":"https://avatars.githubusercontent.com/u/230453?v=3","gravatar_id":"","url":"https://api.github.com/users/ipython","html_url":"https://github.com/ipython","followers_url":"https://api.github.com/users/ipython/followers","following_url":"https://api.github.com/users/ipython/following{/other_user}","gists_url":"https://api.github.com/users/ipython/gists{/gist_id}","starred_url":"https://api.github.com/users/ipython/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ipython/subscriptions","organizations_url":"https://api.github.com/users/ipython/orgs","repos_url":"https://api.github.com/users/ipython/repos","events_url":"https://api.github.com/users/ipython/events{/privacy}","received_events_url":"https://api.github.com/users/ipython/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ipython/ipython","description":"Official repository for IPython itself. Other repos in the IPython organization contain things like the website, documentation builds, etc.","fork":false,"url":"https://api.github.com/repos/ipython/ipython","forks_url":"https://api.github.com/repos/ipython/ipython/forks","keys_url":"https://api.github.com/repos/ipython/ipython/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ipython/ipython/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ipython/ipython/teams","hooks_url":"https://api.github.com/repos/ipython/ipython/hooks","issue_events_url":"https://api.github.com/repos/ipython/ipython/issues/events{/number}","events_url":"https://api.github.com/repos/ipython/ipython/events","assignees_url":"https://api.github.com/repos/ipython/ipython/assignees{/user}","branches_url":"https://api.github.com/repos/ipython/ipython/branches{/branch}","tags_url":"https://api.github.com/repos/ipython/ipython/tags","blobs_url":"https://api.github.com/repos/ipython/ipython/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ipython/ipython/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ipython/ipython/git/refs{/sha}","trees_url":"https://api.github.com/repos/ipython/ipython/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ipython/ipython/statuses/{sha}","languages_url":"https://api.github.com/repos/ipython/ipython/languages","stargazers_url":"https://api.github.com/repos/ipython/ipython/stargazers","contributors_url":"https://api.github.com/repos/ipython/ipython/contributors","subscribers_url":"https://api.github.com/repos/ipython/ipython/subscribers","subscription_url":"https://api.github.com/repos/ipython/ipython/subscription","commits_url":"https://api.github.com/repos/ipython/ipython/commits{/sha}","git_commits_url":"https://api.github.com/repos/ipython/ipython/git/commits{/sha}","comments_url":"https://api.github.com/repos/ipython/ipython/comments{/number}","issue_comment_url":"https://api.github.com/repos/ipython/ipython/issues/comments/{number}","contents_url":"https://api.github.com/repos/ipython/ipython/contents/{+path}","compare_url":"https://api.github.com/repos/ipython/ipython/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ipython/ipython/merges","archive_url":"https://api.github.com/repos/ipython/ipython/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ipython/ipython/downloads","issues_url":"https://api.github.com/repos/ipython/ipython/issues{/number}","pulls_url":"https://api.github.com/repos/ipython/ipython/pulls{/number}","milestones_url":"https://api.github.com/repos/ipython/ipython/milestones{/number}","notifications_url":"https://api.github.com/repos/ipython/ipython/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ipython/ipython/labels{/name}","releases_url":"https://api.github.com/repos/ipython/ipython/releases{/id}","created_at":"2010-05-10T04:46:06Z","updated_at":"2015-02-09T17:21:23Z","pushed_at":"2015-02-09T17:21:23Z","git_url":"git://github.com/ipython/ipython.git","ssh_url":"git@github.com:ipython/ipython.git","clone_url":"https://github.com/ipython/ipython.git","svn_url":"https://github.com/ipython/ipython","homepage":"http://ipython.org","size":105768,"stargazers_count":5700,"watchers_count":5700,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1698,"mirror_url":null,"open_issues_count":763,"forks":1698,"open_issues":763,"watchers":5700,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ipython/ipython/pulls/7706"},"html":{"href":"https://github.com/ipython/ipython/pull/7706"},"issue":{"href":"https://api.github.com/repos/ipython/ipython/issues/7706"},"comments":{"href":"https://api.github.com/repos/ipython/ipython/issues/7706/comments"},"review_comments":{"href":"https://api.github.com/repos/ipython/ipython/pulls/7706/comments"},"review_comment":{"href":"https://api.github.com/repos/ipython/ipython/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/ipython/ipython/pulls/7706/commits"},"statuses":{"href":"https://api.github.com/repos/ipython/ipython/statuses/f18f5551d80d83f5a6cfbcedb281bbe0b8e6cef7"}}}}