Skip to content

Commit 431f024

Browse files
committed
Made killServer() work
1 parent 8bf425b commit 431f024

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

tika/tika.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def make_content_disposition_header(fn):
138138
import platform
139139
from subprocess import Popen
140140
from subprocess import STDOUT
141-
from os import walk, kill
141+
from os import walk
142142
import signal
143143
import logging
144144

@@ -187,8 +187,8 @@ def make_content_disposition_header(fn):
187187
EncodeUtf8 = 0
188188
csvOutput = 0
189189

190-
# Tika server PID, will be used later on to kill the process and free up ram
191-
TikaServerPID = -1
190+
# will be used later on to kill the process and free up ram
191+
TikaServerProcess = ""
192192

193193
class TikaException(Exception):
194194
pass
@@ -662,7 +662,8 @@ def startServer(tikaServerJar, java_path = TikaJava, java_args = TikaJavaArgs, s
662662

663663
# Run java with jar args
664664
# need to check if shell=true is really needed
665-
cmd = Popen(cmd_string, stdout=logFile, stderr=STDOUT, shell=True)
665+
global TikaServerProcess
666+
TikaServerProcess = Popen(cmd_string, stdout=logFile, stderr=STDOUT, shell=True, preexec_fn=os.setsid)
666667

667668
# Check logs and retry as configured
668669
try_count = 0
@@ -681,12 +682,11 @@ def startServer(tikaServerJar, java_path = TikaJava, java_args = TikaJavaArgs, s
681682
log.error("Tika startup log message not received after %d tries." % (TikaStartupMaxRetry))
682683
return False
683684
else:
684-
TikaServerPID = cmd.pid
685685
return True
686686

687687
def killServer():
688-
if(TikaServerPID > 1):
689-
kill(TikaServerPID, signal.SIGTERM)
688+
if(TikaServerProcess.pid > 1):
689+
os.killpg(os.getpgid(TikaServerProcess.pid), signal.SIGTERM)
690690
else:
691691
log.error("Invalid server PID, won't kill")
692692

0 commit comments

Comments
 (0)