{"action":"created","issue":{"url":"https://api.github.com/repos/pallets/werkzeug/issues/844","repository_url":"https://api.github.com/repos/pallets/werkzeug","labels_url":"https://api.github.com/repos/pallets/werkzeug/issues/844/labels{/name}","comments_url":"https://api.github.com/repos/pallets/werkzeug/issues/844/comments","events_url":"https://api.github.com/repos/pallets/werkzeug/issues/844/events","html_url":"https://github.com/pallets/werkzeug/issues/844","id":124352005,"number":844,"title":"Proposal for Live Server Thread","user":{"login":"foxx","id":651797,"avatar_url":"https://avatars.githubusercontent.com/u/651797?v=3","gravatar_id":"","url":"https://api.github.com/users/foxx","html_url":"https://github.com/foxx","followers_url":"https://api.github.com/users/foxx/followers","following_url":"https://api.github.com/users/foxx/following{/other_user}","gists_url":"https://api.github.com/users/foxx/gists{/gist_id}","starred_url":"https://api.github.com/users/foxx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/foxx/subscriptions","organizations_url":"https://api.github.com/users/foxx/orgs","repos_url":"https://api.github.com/users/foxx/repos","events_url":"https://api.github.com/users/foxx/events{/privacy}","received_events_url":"https://api.github.com/users/foxx/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/pallets/werkzeug/labels/waiting","name":"waiting","color":"e6e6e6"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-12-30T14:05:47Z","updated_at":"2016-06-06T13:39:57Z","closed_at":"2016-06-06T13:39:57Z","body":"In situations where you want to run acceptance tests in Python, it can be useful to have the ability to run a WSGI server in a different thread. There is some trickery required to make it work properly, as seen below. \r\n\r\nCan a core maintainer please let me know if this would be considered for merge? If so, I'll put together a fully tested and documented PR.\r\n\r\n```python\r\nimport socket\r\nimport threading\r\nfrom werkzeug.serving import make_server\r\n\r\nclass LiveServerThread(threading.Thread):\r\n    \"\"\"\r\n    Example usage:\r\n\r\n    >>> thread = LiveServerThread(host='127.0.0.1', port='0', app=self.app)\r\n    >>> thread.start()\r\n    >>> print(thread.url)\r\n    http://127.0.0.1:55691\r\n    \"\"\"\r\n\r\n    def __init__(self, *args, **kwargs):\r\n        super().__init__()\r\n        self.daemon = True\r\n        self.server = make_server(*args, **kwargs)\r\n  \r\n    @property\r\n    def url(self):\r\n        return \"http://{}:{}\".format(self.server.server_name, self.server.server_port)\r\n  \r\n    def run(self):\r\n        \"\"\"Called inside thread once started\"\"\"\r\n        self.server.serve_forever()\r\n  \r\n    def stop(self):\r\n        \"\"\"Called outside thread to shutdown\"\"\"\r\n        self.server.shutdown_signal = True\r\n        if self.server and self.is_alive():\r\n            try:\r\n                s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\r\n                s.connect(self.server.socket.getsockname()[:2])\r\n                s.send(b'\\r\\n')\r\n                s.close()\r\n            except IOError:\r\n                import traceback\r\n                traceback.print_exc()\r\n        self.join(5)\r\n```"},"comment":{"url":"https://api.github.com/repos/pallets/werkzeug/issues/comments/223961569","html_url":"https://github.com/pallets/werkzeug/issues/844#issuecomment-223961569","issue_url":"https://api.github.com/repos/pallets/werkzeug/issues/844","id":223961569,"user":{"login":"untitaker","id":837573,"avatar_url":"https://avatars.githubusercontent.com/u/837573?v=3","gravatar_id":"","url":"https://api.github.com/users/untitaker","html_url":"https://github.com/untitaker","followers_url":"https://api.github.com/users/untitaker/followers","following_url":"https://api.github.com/users/untitaker/following{/other_user}","gists_url":"https://api.github.com/users/untitaker/gists{/gist_id}","starred_url":"https://api.github.com/users/untitaker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/untitaker/subscriptions","organizations_url":"https://api.github.com/users/untitaker/orgs","repos_url":"https://api.github.com/users/untitaker/repos","events_url":"https://api.github.com/users/untitaker/events{/privacy}","received_events_url":"https://api.github.com/users/untitaker/received_events","type":"User","site_admin":false},"created_at":"2016-06-06T13:39:57Z","updated_at":"2016-06-06T13:39:57Z","body":"Sorry for responding late -- I don't consider this to be within scope for Werkzeug.\r\n\r\nFor pytest there already is https://bitbucket.org/pytest-dev/pytest-localserver, for other testing frameworks some other API might be more appropriate."}}
{"actor":{"display_login":"untitaker"}}