LoadComponentFromURL crashes and dies, how to do CPR?

Well I am testing my jython program that does some neat [.xls "," .doc "," .rtf "," .tif "," .tiff "," .pdf "files] -> pdf (intermediate file) → tif (final output) using Open Office Due to automation issues we moved away from MS Office Now it seems we have knocked down a lot of bottles related to showing stop order errors, leaving one bottle. OO freezes after a while.

It happens where you see this line '<<<<<<<<<<<<<<<<in the code

What is the correct way to handle a stuck Open Office process. could you please provide some useful links and give me a good suggestion for an exit.
One more question.

Amount:
* How to handle a stuck Open Office instance?
* How do I do the conversion with java headless so I don't have a GUI that pops up all the time, wasting memory.
* Any general guidelines for code quality, optimizations, and general coding standards will also be appreciated.


Traceback (most recent):
File "dcmail.py", line 184, at?
File "dcmail.py", line 174, main page File "C: \ DCMail \ digestemails.py", line 126, in the process_inbox folder
File "C: \ DCMail \ digestemails.py", line 258, in _convert
File "C : \ DCMail \ digestemails.py ", line 284, at _choose_conversion_type
File" C: \ DCMail \ digestemails.py ", at file _open_office_convert
File" C: \ DCMail \ digestemails.py ", at line 299, at _load_attachment_to_convert
com .sun.star.lang.DisposedException: java.io.EOFException
      at com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge $ MessageDi splatch.run (java_remote_bridge.java:176)

com.sun.star.lang.DisposedException: com.sun.star.lang.DisposedException: java.i o.EOFException

Just to clear this exception, only throws when I kill an open office process. Otherwise, the program just waits for the open office to complete. Indefinitely


Code (with non-functional codes)

[code]

#ghost script handles these file types  
GS_WHITELIST=[".pdf"]  
#Open Office handles these file types  
OO_WHITELIST=[".xls", ".doc", ".rtf", ".tif", ".tiff"]   
#whitelist is used to check against any unsupported files.  
WHITELIST=GS_WHITELIST + OO_WHITELIST   

      

def _get_service_manager(self):
    try:
        self._context=Bootstrap.bootstrap();
        self._xMultiCompFactory=self._context.getServiceManager()
        self._xcomponentloader=UnoRuntime.queryInterface(XComponentLoader, self._xMultiCompFactory.createInstanceWithContext("com.sun.star.frame.Desktop", self._context))
    except:
        raise OpenOfficeException("Exception Occurred with Open Office")

def _choose_conversion_type(self,fn):
    ext=os.path.splitext(fn)[1]
    if ext in GS_WHITELIST:
        self._ghostscript_convert_to_tiff(fn)
    elif ext in OO_WHITELIST:
        self._open_office_convert(fn)

def _open_office_convert(self,fn):
    self._load_attachment_to_convert(fn)
    self._save_as_pdf(fn)
    self._ghostscript_convert_to_tiff(fn)

def _load_attachment_to_convert(self, file):
    file=self._create_UNO_File_URL(file)
    properties=[]
    p=PropertyValue()
    p.Name="Hidden"
    p.Value=True
    properties.append(p)
    properties=tuple(properties) 
    self._doc=self._xcomponentloader.loadComponentFromURL(file, "_blank",0, properties) <<<<<<<<<<<<<<< here is line 299

def _create_UNO_File_URL(self, filepath):
    try:
        file=str("file:///" + filepath)
        file=file.replace("\\", "/")
    except MalformedURLException, e:
        raise e
    return file

def _save_as_pdf(self, docSource):
    dirName=os.path.dirname(docSource)
    baseName=os.path.basename(docSource)
    baseName, ext=os.path.splitext(baseName)
    dirTmpPdfConverted=os.path.join(dirName + DIR + PDF_TEMP_CONVERT_DIR)
    if not os.path.exists(dirTmpPdfConverted):
        os.makedirs(dirTmpPdfConverted)
    pdfDest=os.path.join(dirTmpPdfConverted + DIR + baseName + ".pdf")
    url_save=self._create_UNO_File_URL(pdfDest)
    properties=self._create_properties(ext)
    try:
        try:
            self._xstorable=UnoRuntime.queryInterface(XStorable, self._doc);
            self._xstorable.storeToURL(url_save, properties)
        except AttributeError,e:
                self.logger.info("pdf file already created (" + str(e) + ")")
                raise e
    finally:
        try:
            self._doc.dispose()
        except:
            raise

def _create_properties(self,ext):
    properties=[]
    p=PropertyValue()
    p.Name="Overwrite"
    p.Value=True
    properties.append(p)
    p=PropertyValue()
    p.Name="FilterName"
    if   ext==".doc":
        p.Value='writer_pdf_Export'
    elif ext==".rtf":
        p.Value='writer_pdf_Export'
    elif ext==".xls":
        p.Value='calc_pdf_Export'
    elif ext==".tif":
        p.Value='draw_pdf_Export'
    elif ext==".tiff":
        p.Value='draw_pdf_Export'
    properties.append(p)
    return tuple(properties)

def _ghostscript_convert_to_tiff(self, docSource):
    dest, source=self._get_dest_and_source_conversion_file(docSource)
    try:
        command = ' '.join([
            self._ghostscriptPath + 'gswin32c.exe',
           '-q',
           '-dNOPAUSE',
           '-dBATCH',
           '-r500',
           '-sDEVICE=tiffg4',
           '-sPAPERSIZE=a4',
           '-sOutputFile=%s %s' % (dest, source),
           ])
        self._execute_ghostscript(command)
        self.convertedTifDocList.append(dest)
    except OSError, e:
        self.logger.info(e)
        raise e
    except TypeError, (e):
        raise e
    except AttributeError, (e):
        raise e
    except:
        raise

      

[/code]

0


source to share


2 answers


It is not a good solution to have a monitor for the OpenOffice process. If your monitor knows the PID and has privileges, it can receive CPU time every few seconds. If OO hangs in a stopped state (no more CPU) then the monitor can kill it.

The easiest way to deal with this is to have a "wrapper" shoot from an open office task, watch it as it runs, and kill it when it hangs. The parent process has to wait anyway, so it can track as well.



If OpenOffuce hangs in a loop then it gets stiffer. The processor usually goes through the roof, stays there, and the priority drops to the lowest possible priority. Handling or Hanging? Court challenge. You have to let it hang like that "for a while" (choose a random duration, for example 432 seconds (3 dozen), you will always invade yourself).

+1


source


OpenOffice.org has a "-headless" option to run without a GUI. I'm not sure if this actually frees up all the resources to be wasted on the GUI. This is how I start my headless backend server:

soffice -headless -accept="socket,port=1234;urp" -display :25

      



I can't tell what is causing the stopping problems for your Python script, but you can check PyODConverter and see what this script does differently to catch the error that caused your problem.

+1


source







All Articles