{"action":"created","comment":{"url":"https://api.github.com/repos/Pylons/pyramid_cookbook/pulls/comments/201592973","pull_request_review_id":136114631,"id":201592973,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwMTU5Mjk3Mw==","diff_hunk":"@@ -0,0 +1,94 @@\n+Forked and Threaded Servers\n++++++++++++++++++++++++++++\n+\n+Forked and Threaded Servers share common \"gotchas\" and solutions when\n+using pyramid and some popular packages.\n+\n+Forked and Threaded servers tend to use a \"copy on write\" implementation detail\n+to optimize how they work and share memory. This can create problems when\n+certain actions happen before the fork or thread dispatch, such as when files or\n+file-descriptors are opened or random number generators are initialized.\n+\n+Many servers have built-in hooks or events which allow you to easily handle these\n+situations.\n+\n+\n+Servers\n+++++++++++\n+\n+gunicorn\n+========\n+\n+gunicorn offers several hooks during an application lifecycle\n+\n+the postfork routine is provided as a function in a configuration python script.\n+\n+for example a script 'config.py' might look like:\n+\n+\tdef post_fork(server, worker):\n+\t\tlog.debug(\"gunicorn - post_fork\")\n+\n+and invoking the script would look like:\n+\n+\tgunicorn --paste production.ini -c config.py\n+\n+documentation for the `post_fork` hook appears on http://docs.gunicorn.org/en/latest/settings.html#post-fork\n+\n+\n+uwsgi\n+========\n+\n+uwsgi offers a decorator to handle forking\n+\n+your application would include code like\n+\n+    from uwsgidecorators import postfork\n+    \n+    @postfork\n+    def my_setup():\n+\t\tlog.debug(\"uwsgi - postfork\")\n+\n+documentation for the `postfork` decorator appears on https://uwsgi-docs.readthedocs.io/en/latest/PythonDecorators.html#uwsgidecorators.postfork\n+\n+\n+waitress\n+========\n+\n+waitress is not a forking server, but it's threads can create similar issues as forking servers\n+\n+\n+Known Packages\n+++++++++++++++\n+\n+\n+SqlAlchemy\n+============\n+\n+Many people use SqlAlchemy as part of their pyramid application stack.\n+\n+The database connections and the connection pools in SqlAlchemy are not safe to\n+share across process boundaries (forks and threads). The connections and \n+connection pools are lazily created on their first use, so most pyramid users \n+will not encounter an issue as database interaction usually happens on a \n+per-request basis.\n+\n+If your pyramid application connects to a database during the application startup\n+however, then you must use 'Engine.dispose' to reset the connections.  It might\n+look something like this:\n+\n+    @postfork\n+    def reset_sqlalchemy():\n+        models.engine.dispose()\n+\n+Additional documentation on this topic is available from SqlAlchemy's docs:\n+\n+* http://docs.sqlalchemy.org/en/latest/core/pooling.html#using-connection-pools-with-multiprocessing\n+* http://docs.sqlalchemy.org/en/latest/core/connections.html#engine-disposal\n+\n+\n+PyCrypto\n+============\n+\n+The pycrypto library provides for a `Crypto.Random.atfork` function to reseed the","path":"docs/deployment/forked_threaded_servers.rst","position":92,"original_position":92,"commit_id":"e0d131bfe9325378c339f47f6db8e16ec636e690","original_commit_id":"e0d131bfe9325378c339f47f6db8e16ec636e690","user":{"login":"stevepiercy","id":102112,"node_id":"MDQ6VXNlcjEwMjExMg==","avatar_url":"https://avatars1.githubusercontent.com/u/102112?v=4","gravatar_id":"","url":"https://api.github.com/users/stevepiercy","html_url":"https://github.com/stevepiercy","followers_url":"https://api.github.com/users/stevepiercy/followers","following_url":"https://api.github.com/users/stevepiercy/following{/other_user}","gists_url":"https://api.github.com/users/stevepiercy/gists{/gist_id}","starred_url":"https://api.github.com/users/stevepiercy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevepiercy/subscriptions","organizations_url":"https://api.github.com/users/stevepiercy/orgs","repos_url":"https://api.github.com/users/stevepiercy/repos","events_url":"https://api.github.com/users/stevepiercy/events{/privacy}","received_events_url":"https://api.github.com/users/stevepiercy/received_events","type":"User","site_admin":false},"body":"```\r\nThe `PyCrypto <https://www.dlitz.net/software/pycrypto/>`_ library\r\n```","created_at":"2018-07-11T07:45:31Z","updated_at":"2018-07-11T07:49:44Z","html_url":"https://github.com/Pylons/pyramid_cookbook/pull/206#discussion_r201592973","pull_request_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/pulls/206","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/Pylons/pyramid_cookbook/pulls/comments/201592973"},"html":{"href":"https://github.com/Pylons/pyramid_cookbook/pull/206#discussion_r201592973"},"pull_request":{"href":"https://api.github.com/repos/Pylons/pyramid_cookbook/pulls/206"}}},"pull_request":{"url":"https://api.github.com/repos/Pylons/pyramid_cookbook/pulls/206","id":200490032,"node_id":"MDExOlB1bGxSZXF1ZXN0MjAwNDkwMDMy","html_url":"https://github.com/Pylons/pyramid_cookbook/pull/206","diff_url":"https://github.com/Pylons/pyramid_cookbook/pull/206.diff","patch_url":"https://github.com/Pylons/pyramid_cookbook/pull/206.patch","issue_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/issues/206","number":206,"state":"open","locked":false,"title":"added a note about forking/threaded servers for deployment","user":{"login":"jvanasco","id":204779,"node_id":"MDQ6VXNlcjIwNDc3OQ==","avatar_url":"https://avatars3.githubusercontent.com/u/204779?v=4","gravatar_id":"","url":"https://api.github.com/users/jvanasco","html_url":"https://github.com/jvanasco","followers_url":"https://api.github.com/users/jvanasco/followers","following_url":"https://api.github.com/users/jvanasco/following{/other_user}","gists_url":"https://api.github.com/users/jvanasco/gists{/gist_id}","starred_url":"https://api.github.com/users/jvanasco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jvanasco/subscriptions","organizations_url":"https://api.github.com/users/jvanasco/orgs","repos_url":"https://api.github.com/users/jvanasco/repos","events_url":"https://api.github.com/users/jvanasco/events{/privacy}","received_events_url":"https://api.github.com/users/jvanasco/received_events","type":"User","site_admin":false},"body":"I saw the tweet about UWSGI recipes and felt compelled to submit this PR noting \"special considerations\" for forked/threaded servers (like uwsgi)\r\n\r\nI'm sorry if the formatting is off, it's been a while since i've used REST.","created_at":"2018-07-10T18:47:06Z","updated_at":"2018-07-11T07:49:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9e323c81d00ebc4047ad84215b78d38905aed804","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/pulls/206/commits","review_comments_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/pulls/206/comments","review_comment_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/issues/206/comments","statuses_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/statuses/e0d131bfe9325378c339f47f6db8e16ec636e690","head":{"label":"jvanasco:feature-deployment_postfork","ref":"feature-deployment_postfork","sha":"e0d131bfe9325378c339f47f6db8e16ec636e690","user":{"login":"jvanasco","id":204779,"node_id":"MDQ6VXNlcjIwNDc3OQ==","avatar_url":"https://avatars3.githubusercontent.com/u/204779?v=4","gravatar_id":"","url":"https://api.github.com/users/jvanasco","html_url":"https://github.com/jvanasco","followers_url":"https://api.github.com/users/jvanasco/followers","following_url":"https://api.github.com/users/jvanasco/following{/other_user}","gists_url":"https://api.github.com/users/jvanasco/gists{/gist_id}","starred_url":"https://api.github.com/users/jvanasco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jvanasco/subscriptions","organizations_url":"https://api.github.com/users/jvanasco/orgs","repos_url":"https://api.github.com/users/jvanasco/repos","events_url":"https://api.github.com/users/jvanasco/events{/privacy}","received_events_url":"https://api.github.com/users/jvanasco/received_events","type":"User","site_admin":false},"repo":{"id":140470588,"node_id":"MDEwOlJlcG9zaXRvcnkxNDA0NzA1ODg=","name":"pyramid_cookbook","full_name":"jvanasco/pyramid_cookbook","owner":{"login":"jvanasco","id":204779,"node_id":"MDQ6VXNlcjIwNDc3OQ==","avatar_url":"https://avatars3.githubusercontent.com/u/204779?v=4","gravatar_id":"","url":"https://api.github.com/users/jvanasco","html_url":"https://github.com/jvanasco","followers_url":"https://api.github.com/users/jvanasco/followers","following_url":"https://api.github.com/users/jvanasco/following{/other_user}","gists_url":"https://api.github.com/users/jvanasco/gists{/gist_id}","starred_url":"https://api.github.com/users/jvanasco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jvanasco/subscriptions","organizations_url":"https://api.github.com/users/jvanasco/orgs","repos_url":"https://api.github.com/users/jvanasco/repos","events_url":"https://api.github.com/users/jvanasco/events{/privacy}","received_events_url":"https://api.github.com/users/jvanasco/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jvanasco/pyramid_cookbook","description":"Pyramid cookbook recipes (documentation)","fork":true,"url":"https://api.github.com/repos/jvanasco/pyramid_cookbook","forks_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/forks","keys_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/teams","hooks_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/hooks","issue_events_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/issues/events{/number}","events_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/events","assignees_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/assignees{/user}","branches_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/branches{/branch}","tags_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/tags","blobs_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/git/refs{/sha}","trees_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/statuses/{sha}","languages_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/languages","stargazers_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/stargazers","contributors_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/contributors","subscribers_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/subscribers","subscription_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/subscription","commits_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/commits{/sha}","git_commits_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/git/commits{/sha}","comments_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/comments{/number}","issue_comment_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/issues/comments{/number}","contents_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/contents/{+path}","compare_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/merges","archive_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/downloads","issues_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/issues{/number}","pulls_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/pulls{/number}","milestones_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/milestones{/number}","notifications_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/labels{/name}","releases_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/releases{/id}","deployments_url":"https://api.github.com/repos/jvanasco/pyramid_cookbook/deployments","created_at":"2018-07-10T18:09:16Z","updated_at":"2018-07-10T18:09:18Z","pushed_at":"2018-07-10T19:58:01Z","git_url":"git://github.com/jvanasco/pyramid_cookbook.git","ssh_url":"git@github.com:jvanasco/pyramid_cookbook.git","clone_url":"https://github.com/jvanasco/pyramid_cookbook.git","svn_url":"https://github.com/jvanasco/pyramid_cookbook","homepage":"http://docs.pylonsproject.org/projects/pyramid-cookbook/en/latest/","size":4276,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"Pylons:master","ref":"master","sha":"c51d24c914efa19a11aab3b3a8401fcc781fb253","user":{"login":"Pylons","id":452227,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ1MjIyNw==","avatar_url":"https://avatars1.githubusercontent.com/u/452227?v=4","gravatar_id":"","url":"https://api.github.com/users/Pylons","html_url":"https://github.com/Pylons","followers_url":"https://api.github.com/users/Pylons/followers","following_url":"https://api.github.com/users/Pylons/following{/other_user}","gists_url":"https://api.github.com/users/Pylons/gists{/gist_id}","starred_url":"https://api.github.com/users/Pylons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pylons/subscriptions","organizations_url":"https://api.github.com/users/Pylons/orgs","repos_url":"https://api.github.com/users/Pylons/repos","events_url":"https://api.github.com/users/Pylons/events{/privacy}","received_events_url":"https://api.github.com/users/Pylons/received_events","type":"Organization","site_admin":false},"repo":{"id":1198154,"node_id":"MDEwOlJlcG9zaXRvcnkxMTk4MTU0","name":"pyramid_cookbook","full_name":"Pylons/pyramid_cookbook","owner":{"login":"Pylons","id":452227,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQ1MjIyNw==","avatar_url":"https://avatars1.githubusercontent.com/u/452227?v=4","gravatar_id":"","url":"https://api.github.com/users/Pylons","html_url":"https://github.com/Pylons","followers_url":"https://api.github.com/users/Pylons/followers","following_url":"https://api.github.com/users/Pylons/following{/other_user}","gists_url":"https://api.github.com/users/Pylons/gists{/gist_id}","starred_url":"https://api.github.com/users/Pylons/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Pylons/subscriptions","organizations_url":"https://api.github.com/users/Pylons/orgs","repos_url":"https://api.github.com/users/Pylons/repos","events_url":"https://api.github.com/users/Pylons/events{/privacy}","received_events_url":"https://api.github.com/users/Pylons/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Pylons/pyramid_cookbook","description":"Pyramid cookbook recipes (documentation)","fork":false,"url":"https://api.github.com/repos/Pylons/pyramid_cookbook","forks_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/forks","keys_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/teams","hooks_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/hooks","issue_events_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/issues/events{/number}","events_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/events","assignees_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/assignees{/user}","branches_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/branches{/branch}","tags_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/tags","blobs_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/git/refs{/sha}","trees_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/statuses/{sha}","languages_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/languages","stargazers_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/stargazers","contributors_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/contributors","subscribers_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/subscribers","subscription_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/subscription","commits_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/commits{/sha}","git_commits_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/git/commits{/sha}","comments_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/comments{/number}","issue_comment_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/issues/comments{/number}","contents_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/contents/{+path}","compare_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/merges","archive_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/downloads","issues_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/issues{/number}","pulls_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/pulls{/number}","milestones_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/milestones{/number}","notifications_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/labels{/name}","releases_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/releases{/id}","deployments_url":"https://api.github.com/repos/Pylons/pyramid_cookbook/deployments","created_at":"2010-12-26T05:21:21Z","updated_at":"2018-07-11T02:05:35Z","pushed_at":"2018-07-11T00:56:38Z","git_url":"git://github.com/Pylons/pyramid_cookbook.git","ssh_url":"git@github.com:Pylons/pyramid_cookbook.git","clone_url":"https://github.com/Pylons/pyramid_cookbook.git","svn_url":"https://github.com/Pylons/pyramid_cookbook","homepage":"http://docs.pylonsproject.org/projects/pyramid-cookbook/en/latest/","size":4270,"stargazers_count":172,"watchers_count":172,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":125,"mirror_url":null,"archived":false,"open_issues_count":7,"license":null,"forks":125,"open_issues":7,"watchers":172,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Pylons/pyramid_cookbook/pulls/206"},"html":{"href":"https://github.com/Pylons/pyramid_cookbook/pull/206"},"issue":{"href":"https://api.github.com/repos/Pylons/pyramid_cookbook/issues/206"},"comments":{"href":"https://api.github.com/repos/Pylons/pyramid_cookbook/issues/206/comments"},"review_comments":{"href":"https://api.github.com/repos/Pylons/pyramid_cookbook/pulls/206/comments"},"review_comment":{"href":"https://api.github.com/repos/Pylons/pyramid_cookbook/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Pylons/pyramid_cookbook/pulls/206/commits"},"statuses":{"href":"https://api.github.com/repos/Pylons/pyramid_cookbook/statuses/e0d131bfe9325378c339f47f6db8e16ec636e690"}},"author_association":"NONE"}}
{"actor":{"display_login":"stevepiercy"}}