Commit 5102981a authored by Boris Kocherov's avatar Boris Kocherov

fix deadlock in uno thread

parent 8f3d6526
...@@ -126,11 +126,14 @@ class Handler(object): ...@@ -126,11 +126,14 @@ class Handler(object):
if pid_exists(process.pid): if pid_exists(process.pid):
logger.debug("Process %s terminated", process.pid) logger.debug("Process %s terminated", process.pid)
process.terminate() process.terminate()
if (process.returncode < 0 and process.returncode != -6) or stderr: if (process.returncode != -3) or stderr:
logger.error("Process %s command:%s", process.pid, " ".join(command_list)) logger.error("Process %s command:%s", process.pid, " ".join(command_list))
logger.error("Process %s stdout:%s", process.pid, stdout) logger.error("Process %s stdout:%s", process.pid, stdout)
logger.error("Process %s stderr:%s", process.pid, stderr) logger.error("Process %s stderr:%s", process.pid, stderr)
logger.debug("Process %s terminated with returncode %s", process.pid, process.returncode) logger.debug("Process %s terminated with returncode %s", process.pid, process.returncode)
if process.returncode != -3:
raise ValueError("unocnverter.py should always be interrupted by external signal,"
" otherwise deadlock can be raised")
return stdout, stderr return stdout, stderr
def _callUnoConverter(self, *feature_list, **kw): def _callUnoConverter(self, *feature_list, **kw):
......
import signal
import sys import sys
import os import os
import time import time
...@@ -31,3 +32,13 @@ def getServiceManager(host, port, uno_path, office_binary_path): ...@@ -31,3 +32,13 @@ def getServiceManager(host, port, uno_path, office_binary_path):
time.sleep(1) time.sleep(1)
# Get the ServiceManager object # Get the ServiceManager object
return uno_connection.ServiceManager return uno_connection.ServiceManager
def exitOverAbort(main_func):
try:
main_func()
except:
import traceback
sys.stderr.write(traceback.format_exc())
sys.stdout.flush()
sys.stderr.flush()
os.kill(os.getpid(), signal.SIGQUIT)
\ No newline at end of file
...@@ -37,4 +37,4 @@ def main(): ...@@ -37,4 +37,4 @@ def main():
if __name__ == "__main__": if __name__ == "__main__":
main() helper_util.exitOverAbort(main)
\ No newline at end of file
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
# #
############################################################################## ##############################################################################
import os
import sys import sys
import csv import csv
import codecs import codecs
...@@ -367,4 +366,4 @@ def main(): ...@@ -367,4 +366,4 @@ def main():
sys.stdout.write(output) sys.stdout.write(output)
if "__main__" == __name__: if "__main__" == __name__:
main() helper_util.exitOverAbort(main)
\ No newline at end of file
...@@ -141,4 +141,4 @@ def main(): ...@@ -141,4 +141,4 @@ def main():
sort_keys=True, indent=2, separators=(',', ':'))) sort_keys=True, indent=2, separators=(',', ':')))
if "__main__" == __name__: if "__main__" == __name__:
main() helper_util.exitOverAbort(main)
\ No newline at end of file
...@@ -129,7 +129,6 @@ class MimeMapper(object): ...@@ -129,7 +129,6 @@ class MimeMapper(object):
stdout, stderr = process.communicate() stdout, stderr = process.communicate()
if stderr: if stderr:
logger.error(stderr) logger.error(stderr)
if process.returncode:
raise ValueError(stdout) raise ValueError(stdout)
filter_dict, type_dict = json.loads(stdout) filter_dict, type_dict = json.loads(stdout)
......
...@@ -75,9 +75,9 @@ class TestUnoConverter(HandlerTestCase): ...@@ -75,9 +75,9 @@ class TestUnoConverter(HandlerTestCase):
"--destination_format=%s" % "doc", "--destination_format=%s" % "doc",
"--source_format=%s" % "odt", "--source_format=%s" % "odt",
"--mimemapper=%s" % mimemapper_pickled] "--mimemapper=%s" % mimemapper_pickled]
stdout, stderr = Popen(command, process = Popen(command, stdout=PIPE, stderr=PIPE)
stdout=PIPE, stdout, stderr = process.communicate()
stderr=PIPE).communicate() self.assertEquals(process.returncode, -3)
self.assertEquals(stderr, '') self.assertEquals(stderr, '')
output_url = stdout.replace('\n', '') output_url = stdout.replace('\n', '')
self.assertTrue(exists(output_url), stdout) self.assertTrue(exists(output_url), stdout)
......
...@@ -63,9 +63,9 @@ class TestUnoMimeMapper(HandlerTestCase): ...@@ -63,9 +63,9 @@ class TestUnoMimeMapper(HandlerTestCase):
"--office_binary_path=%s" % self.office_binary_path, "--office_binary_path=%s" % self.office_binary_path,
"--hostname=%s" % self.hostname, "--hostname=%s" % self.hostname,
"--port=%s" % self.openoffice_port] "--port=%s" % self.openoffice_port]
stdout, stderr = Popen(command, process = Popen(command, stdout=PIPE, stderr=PIPE)
stdout=PIPE, stdout, stderr = process.communicate()
stderr=PIPE).communicate() self.assertEquals(process.returncode, -15)
self.assertEquals(stderr, '') self.assertEquals(stderr, '')
filter_dict, type_dict = json.loads(stdout) filter_dict, type_dict = json.loads(stdout)
self.assertTrue('filter_dict' in locals()) self.assertTrue('filter_dict' in locals())
...@@ -84,9 +84,9 @@ class TestUnoMimeMapper(HandlerTestCase): ...@@ -84,9 +84,9 @@ class TestUnoMimeMapper(HandlerTestCase):
"/helper/unomimemapper.py"), "/helper/unomimemapper.py"),
"--hostname=%s" % self.hostname, "--hostname=%s" % self.hostname,
"--port=%s" % self.openoffice_port] "--port=%s" % self.openoffice_port]
stdout, stderr = Popen(command, process = Popen(command, stdout=PIPE, stderr=PIPE)
stdout=PIPE, stdout, stderr = process.communicate()
stderr=PIPE).communicate() self.assertEquals(process.returncode, -3)
self.assertEquals(stderr, '') self.assertEquals(stderr, '')
filter_dict, type_dict = json.loads(stdout) filter_dict, type_dict = json.loads(stdout)
self.assertTrue('filter_dict' in locals()) self.assertTrue('filter_dict' in locals())
...@@ -110,9 +110,9 @@ class TestUnoMimeMapper(HandlerTestCase): ...@@ -110,9 +110,9 @@ class TestUnoMimeMapper(HandlerTestCase):
"--office_binary_path=%s" % self.office_binary_path, "--office_binary_path=%s" % self.office_binary_path,
"--hostname=%s" % self.hostname, "--hostname=%s" % self.hostname,
"--port=%s" % self.openoffice_port] "--port=%s" % self.openoffice_port]
stdout, stderr = Popen(command, process = Popen(command, stdout=PIPE, stderr=PIPE)
stdout=PIPE, stdout, stderr = process.communicate()
stderr=PIPE).communicate() self.assertEquals(process.returncode, -3)
self.assertEquals(stdout, '') self.assertEquals(stdout, '')
self.assertTrue(stderr.endswith(error_msg), stderr) self.assertTrue(stderr.endswith(error_msg), stderr)
openoffice.start() openoffice.start()
......
Markdown is supported
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