Commits

Yuya Nishihara committed 1f77f62

try process-based serve

Comments (0)

Files changed (3)

+serve-usecmda.diff
+serve-useproc.diff
 cmdui-useagent.diff
 cmdcore-sessinit.diff
 cmdcore-sesspriv.diff

serve-usecmda.diff

+# HG changeset patch
+# Parent e21dd67c2064936d81fec73acdef6cea2cd5498f
+serve: use cmda XXX
+
+XXX self._session isn't cleared.
+
+diff --git a/tortoisehg/hgqt/serve.py b/tortoisehg/hgqt/serve.py
+--- a/tortoisehg/hgqt/serve.py
++++ b/tortoisehg/hgqt/serve.py
+@@ -11,7 +11,7 @@ from PyQt4.QtGui import *
+ from mercurial import extensions, hgweb, util, error
+ from mercurial.hgweb import server  # workaround for demandimport
+ from tortoisehg.util import paths, wconfig, hglib
+-from tortoisehg.hgqt import cmdui, qtlib, thgrepo
++from tortoisehg.hgqt import cmdcore, cmdui, qtlib, thgrepo
+ from tortoisehg.hgqt.i18n import _
+ from tortoisehg.hgqt.serve_ui import Ui_ServeDialog
+ from tortoisehg.hgqt.webconf import WebconfForm
+@@ -34,13 +34,13 @@ class ServeDialog(QDialog):
+         self._updateform()
+ 
+     def _initcmd(self):
+-        self._cmd = cmdui.Widget(True, False, self)
+         # TODO: forget old logs?
+-        self._log_edit = self._cmd.core.outputLog
++        self._log_edit = cmdui.LogWidget(self)
+         self._qui.details_tabs.addTab(self._log_edit, _('Log'))
+-        self._cmd.hide()
+-        self._cmd.commandStarted.connect(self._updateform)
+-        self._cmd.commandFinished.connect(self._updateform)
++        self._agent = cmdcore.CmdAgent(self)
++        self._agent.outputReceived.connect(self._log_edit.appendLog)
++        self._agent.busyChanged.connect(self._updateform)
++        self._session = None
+ 
+     def _initwebconf(self, webconf):
+         self._webconf_form = WebconfForm(webconf=webconf, parent=self)
+@@ -77,7 +77,7 @@ class ServeDialog(QDialog):
+             return
+ 
+         _setupwrapper()
+-        self._cmd.run(self._cmdargs())
++        self._session = self._agent.runCommand(map(hglib.tounicode, self._cmdargs()))
+ 
+     def _cmdargs(self):
+         """Build command args to run server"""
+@@ -122,7 +122,7 @@ class ServeDialog(QDialog):
+         if not self.isstarted():
+             return
+ 
+-        self._cmd.cancel()
++        self._session.cancel()  # XXX abort
+         self._fake_request()
+ 
+     def _fake_request(self):
+@@ -148,7 +148,8 @@ class ServeDialog(QDialog):
+ 
+     def isstarted(self):
+         """Is the web server running?"""
+-        return self._cmd.core.running()
++        # XXX return bool(self._session)
++        return self._agent.isBusy()
+ 
+     @property
+     def rooturl(self):

serve-useproc.diff

+# HG changeset patch
+# Parent 60d7789abdb1e1d7e7f6e0611e1bf3579d06400a
+
+diff --git a/tortoisehg/hgqt/serve.py b/tortoisehg/hgqt/serve.py
+--- a/tortoisehg/hgqt/serve.py
++++ b/tortoisehg/hgqt/serve.py
+@@ -9,7 +9,6 @@ import sys, os, httplib, socket, tempfil
+ from PyQt4.QtCore import *
+ from PyQt4.QtGui import *
+ from mercurial import extensions, hgweb, util, error
+-from mercurial.hgweb import server  # workaround for demandimport
+ from tortoisehg.util import paths, wconfig, hglib
+ from tortoisehg.hgqt import cmdcore, cmdui, qtlib, thgrepo
+ from tortoisehg.hgqt.i18n import _
+@@ -76,8 +75,8 @@ class ServeDialog(QDialog):
+         if self.isstarted():
+             return
+ 
+-        _setupwrapper()
+-        self._session = self._agent.runCommand(map(hglib.tounicode, self._cmdargs()))
++        self._session = self._agent.runCommand(map(hglib.tounicode, self._cmdargs()),
++                                               worker='proc')
+ 
+     def _cmdargs(self):
+         """Build command args to run server"""
+@@ -123,24 +122,6 @@ class ServeDialog(QDialog):
+             return
+ 
+         self._session.cancel()  # XXX abort
+-        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()
+@@ -207,46 +188,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()