Commit a5157949 authored by Yusei Tahara's avatar Yusei Tahara

Retry connection. NoConnectException sometimes occurs.

parent 3ff2d0a7
import sys import sys
import os import os
import time
def getServiceManager(host, port, uno_path, office_binary_path): def getServiceManager(host, port, uno_path, office_binary_path):
"""Get the ServiceManager from the running OpenOffice.org. """Get the ServiceManager from the running OpenOffice.org.
...@@ -20,6 +21,13 @@ def getServiceManager(host, port, uno_path, office_binary_path): ...@@ -20,6 +21,13 @@ def getServiceManager(host, port, uno_path, office_binary_path):
uno_context) uno_context)
# Connect to the running OpenOffice.org and get its # Connect to the running OpenOffice.org and get its
# context. # context.
# Retry 10 times if needed.
for i in range(10):
try:
uno_connection = resolver.resolve("uno:socket,host=%s,port=%s;urp;StarOffice.ComponentContext" % (host, port)) uno_connection = resolver.resolve("uno:socket,host=%s,port=%s;urp;StarOffice.ComponentContext" % (host, port))
break
except:
# I don't know how to import com.sun.star.connection.NoConnectException
time.sleep(1)
# Get the ServiceManager object # Get the ServiceManager object
return uno_connection.ServiceManager return uno_connection.ServiceManager
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