Commit 68c628e5 authored by Jean-Francois Dockes's avatar Jean-Francois Dockes
Browse files

run the http server as a separate process to avoid stdout pollution

parent 09bac300
......@@ -24,6 +24,7 @@ import conftree
import cmdtalkplugin
import urllib
import threading
import subprocess
import uprclfolders
import uprcltags
......@@ -79,14 +80,34 @@ def uprcl_init():
uprcluntagged.recoll2untagged(g_rcldocs)
host,port = httphp.split(':')
httpthread = threading.Thread(target=uprclhttp.runHttp,
kwargs = {'host':host ,
'port':int(port),
'pathmap':pathmap,
'pathprefix':pathprefix})
httpthread.daemon = True
httpthread.start()
if False:
# Running the server as a thread. We get into trouble because
# something somewhere writes to stdout a bunch of --------.
# Could not find where they come from, happens after a sigpipe
# when a client closes a stream. The --- seem to happen before
# and after the exception strack trace, e.g:
# ----------------------------------------
# Exception happened during processing of request from ('192...
# Traceback...
# [...]
# error: [Errno 32] Broken pipe
# ----------------------------------------
httpthread = threading.Thread(target=uprclhttp.runHttp,
kwargs = {'host':host ,
'port':int(port),
'pthstr':pthstr,
'pathprefix':pathprefix})
httpthread.daemon = True
httpthread.start()
else:
# Running the HTTP server as a separate process
cmdpath = os.path.join(os.path.dirname(sys.argv[0]), 'uprclhttp.py')
cmd = subprocess.Popen((cmdpath, host, port, pthstr, pathprefix),
stdin = open('/dev/null'),
stdout = sys.stderr,
stderr = sys.stderr,
close_fds = True)
@dispatcher.record('trackuri')
def trackuri(a):
# This is used for plugins which generate temporary local urls
......
......@@ -19,6 +19,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
import SocketServer
import BaseHTTPServer
......@@ -30,6 +31,8 @@ import urllib
import cgi
import shutil
import mimetypes
import sys
try:
from cStringIO import StringIO
except ImportError:
......@@ -193,8 +196,13 @@ class ThreadingSimpleServer(SocketServer.ThreadingMixIn,
pass
def runHttp(host='', port=8080, pathprefix='', pathmap={}):
def runHttp(host='', port=8080, pthstr='', pathprefix=''):
lpth = pthstr.split(',')
pathmap = {}
for ptt in lpth:
l = ptt.split(':')
pathmap[l[0]] = l[1]
# Set pathmap as request handler class variable
RangeHTTPRequestHandler.uprclpathmap = pathmap
RangeHTTPRequestHandler.uprclpathprefix = pathprefix
......@@ -202,3 +210,11 @@ def runHttp(host='', port=8080, pathprefix='', pathmap={}):
server = ThreadingSimpleServer((host, port), RangeHTTPRequestHandler)
while 1:
server.handle_request()
if __name__ == '__main__':
if len(sys.argv) != 5:
print("Usage: uprclhttp.py <host> <port> <pthmap> <pthprefix>",
file=sys.stderr)
sys.exit(1)
runHttp(host=sys.argv[1], port = int(sys.argv[2]), pthstr=sys.argv[3],
pathprefix=sys.argv[4])
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment