Yuya Nishihara avatar Yuya Nishihara committed fc98f0b

serve useproc simple

Comments (0)

Files changed (2)

+serve-useproc-early.diff
 cmdui-useagent.diff
 cmdcore-nostartedsig.diff
 cmdcore-sessinit.diff

serve-useproc-early.diff

+# HG changeset patch
+# Date 1378022851 -32400
+# Parent 705468a76be5792b98c1eb7ef7eaa3feb6c10444
+serve: run hgweb in separate process
+
+It can eliminate several dirty hacks, and will contribute to the stability.
+
+diff --git a/tortoisehg/hgqt/serve.py b/tortoisehg/hgqt/serve.py
+--- a/tortoisehg/hgqt/serve.py
++++ b/tortoisehg/hgqt/serve.py
+@@ -5,11 +5,10 @@
+ # This software may be used and distributed according to the terms of the
+ # GNU General Public License version 2, incorporated herein by reference.
+ 
+-import sys, os, httplib, socket, tempfile
++import os, tempfile
+ from PyQt4.QtCore import *
+ from PyQt4.QtGui import *
+-from mercurial import extensions, hgweb, util, error
+-from mercurial.hgweb import server  # workaround for demandimport
++from mercurial import util, error
+ from tortoisehg.util import paths, wconfig, hglib
+ from tortoisehg.hgqt import cmdui, qtlib, thgrepo
+ from tortoisehg.hgqt.i18n import _
+@@ -76,8 +75,7 @@ class ServeDialog(QDialog):
+         if self.isstarted():
+             return
+ 
+-        _setupwrapper()
+-        self._cmd.run(self._cmdargs())
++        self._cmd.run(self._cmdargs(), useproc=True)
+ 
+     def _cmdargs(self):
+         """Build command args to run server"""
+@@ -123,24 +121,6 @@ class ServeDialog(QDialog):
+             return
+ 
+         self._cmd.cancel()
+-        self._fake_request()
+-
+-    def _fake_request(self):
+-        """Send fake request for server to run python code"""
+-        TIMEOUT = 0.5  # [sec]
+-        conn = httplib.HTTPConnection('localhost:%d' % self.port)
+-        origtimeout = socket.getdefaulttimeout()
+-        socket.setdefaulttimeout(TIMEOUT)
+-        try:
+-            try:
+-                conn.request('GET', '/')
+-                res = conn.getresponse()
+-                res.read()
+-            except (socket.error, httplib.HTTPException):
+-                pass
+-        finally:
+-            socket.setdefaulttimeout(origtimeout)
+-            conn.close()
+ 
+     def reject(self):
+         self.stop()
+@@ -206,46 +186,6 @@ class ServeDialog(QDialog):
+         from tortoisehg.hgqt import settings
+         settings.SettingsDialog(parent=self, focus='web.name').exec_()
+ 
+-def _create_server(orig, ui, app):
+-    """wrapper for hgweb.server.create_server to be interruptable"""
+-    server = orig(ui, app)
+-    server.accesslog = ui
+-    server.errorlog = ui  # TODO: ui.warn
+-    server._serving = False
+-
+-    def serve_forever(orig):
+-        server._serving = True
+-        try:
+-            try:
+-                while server._serving:
+-                    server.handle_request()
+-            except KeyboardInterrupt:
+-                # raised outside try-block around process_request().
+-                # see SocketServer.BaseServer
+-                pass
+-        finally:
+-            server._serving = False
+-            server.server_close()
+-
+-    def handle_error(orig, request, client_address):
+-        type, value, _traceback = sys.exc_info()
+-        if issubclass(type, KeyboardInterrupt):
+-            server._serving = False
+-        else:
+-            ui.write_err('%s\n' % value)
+-
+-    extensions.wrapfunction(server, 'serve_forever', serve_forever)
+-    extensions.wrapfunction(server, 'handle_error', handle_error)
+-    return server
+-
+-_setupwrapper_done = False
+-def _setupwrapper():
+-    """Wrap hgweb.server.create_server to get along with thg"""
+-    global _setupwrapper_done
+-    if not _setupwrapper_done:
+-        extensions.wrapfunction(hgweb.server, 'create_server',
+-                                _create_server)
+-        _setupwrapper_done = True
+ 
+ def run(ui, *pats, **opts):
+     repopath = opts.get('root') or paths.find_root()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.