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

fix deadlock in uno thread

parent 8f3d6526
......@@ -126,11 +126,14 @@ class Handler(object):
if pid_exists(process.pid):
logger.debug("Process %s terminated", process.pid)
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 stdout:%s", process.pid, stdout)
logger.error("Process %s stderr:%s", process.pid, stderr)
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
def _callUnoConverter(self, *feature_list, **kw):
......
import signal
import sys
import os
import time
......@@ -31,3 +32,13 @@ def getServiceManager(host, port, uno_path, office_binary_path):
time.sleep(1)
# Get the ServiceManager object
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():
if __name__ == "__main__":
main()
helper_util.exitOverAbort(main)
\ No newline at end of file
......@@ -27,7 +27,6 @@
#
##############################################################################
import os
import sys
import csv
import codecs
......@@ -367,4 +366,4 @@ def main():
sys.stdout.write(output)
if "__main__" == __name__:
main()
helper_util.exitOverAbort(main)
\ No newline at end of file
......@@ -141,4 +141,4 @@ def main():
sort_keys=True, indent=2, separators=(',', ':')))
if "__main__" == __name__:
main()
helper_util.exitOverAbort(main)
\ No newline at end of file
......@@ -129,7 +129,6 @@ class MimeMapper(object):
stdout, stderr = process.communicate()
if stderr:
logger.error(stderr)
if process.returncode:
raise ValueError(stdout)
filter_dict, type_dict = json.loads(stdout)
......
......@@ -75,9 +75,9 @@ class TestUnoConverter(HandlerTestCase):
"--destination_format=%s" % "doc",
"--source_format=%s" % "odt",
"--mimemapper=%s" % mimemapper_pickled]
stdout, stderr = Popen(command,
stdout=PIPE,
stderr=PIPE).communicate()
process = Popen(command, stdout=PIPE, stderr=PIPE)
stdout, stderr = process.communicate()
self.assertEquals(process.returncode, -3)
self.assertEquals(stderr, '')
output_url = stdout.replace('\n', '')
self.assertTrue(exists(output_url), stdout)
......
......@@ -63,9 +63,9 @@ class TestUnoMimeMapper(HandlerTestCase):
"--office_binary_path=%s" % self.office_binary_path,
"--hostname=%s" % self.hostname,
"--port=%s" % self.openoffice_port]
stdout, stderr = Popen(command,
stdout=PIPE,
stderr=PIPE).communicate()
process = Popen(command, stdout=PIPE, stderr=PIPE)
stdout, stderr = process.communicate()
self.assertEquals(process.returncode, -15)
self.assertEquals(stderr, '')
filter_dict, type_dict = json.loads(stdout)
self.assertTrue('filter_dict' in locals())
......@@ -84,9 +84,9 @@ class TestUnoMimeMapper(HandlerTestCase):
"/helper/unomimemapper.py"),
"--hostname=%s" % self.hostname,
"--port=%s" % self.openoffice_port]
stdout, stderr = Popen(command,
stdout=PIPE,
stderr=PIPE).communicate()
process = Popen(command, stdout=PIPE, stderr=PIPE)
stdout, stderr = process.communicate()
self.assertEquals(process.returncode, -3)
self.assertEquals(stderr, '')
filter_dict, type_dict = json.loads(stdout)
self.assertTrue('filter_dict' in locals())
......@@ -110,9 +110,9 @@ class TestUnoMimeMapper(HandlerTestCase):
"--office_binary_path=%s" % self.office_binary_path,
"--hostname=%s" % self.hostname,
"--port=%s" % self.openoffice_port]
stdout, stderr = Popen(command,
stdout=PIPE,
stderr=PIPE).communicate()
process = Popen(command, stdout=PIPE, stderr=PIPE)
stdout, stderr = process.communicate()
self.assertEquals(process.returncode, -3)
self.assertEquals(stdout, '')
self.assertTrue(stderr.endswith(error_msg), stderr)
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