好吧,我测试了我的jython程序,它做了一些整洁的[“ .xls”,“。doc”,“。rtf”,“。tif”,“。tiff”,“。pdf”文件]-> pdf(中间文件) ->使用Open Office进行tif(最终输出)转换。由于自动化方面的问题,我们离开了MS Office。现在看来,我们已经拆掉了许多与显示塞子错误相关的瓶子,仅剩一瓶。 OO在一段时间后挂起。

会在代码中看到此行'<<<<<<<<<<<<

对我来说,处理停滞的Open Office进程的正确方法是什么?您能否提供有用的链接,并给我一个很好的建议。
还有一个问题。

总结:
*如何处理停滞的Open Office实例?
*如何使Java无头转换,所以我没有一直在浪费内存的GUI弹出。
*还将对任何有关代码质量,优化和通用编码标准的一般建议表示赞赏。



追溯(最里面的最后):
  在第184行的文件“ dcmail.py”中?
  主文件“ dcmail.py”,第174行
  process_inbox中的文件“ C:\ DCMail \ digestemails.py”,第126行
  _convert中的文件“ C:\ DCMail \ digestemails.py”,第258行
  _choose_conversion_type中的文件“ C:\ DCMail \ digestemails.py”,第284行
  _open_office_convert中的文件“ C:\ DCMail \ digestemails.py”,第287行
  _load_attachment_to_convert中的文件“ C:\ DCMail \ digestemails.py”,第299行
com.sun.star.lang.DisposedException:java.io.EOFException
        在com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge $ MessageDi
spatcher.run(java_remote_bridge.java:176)

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

只是为了清除此异常,只有在我终止开放办公室流程时才会抛出该异常。否则,程序将只等待开放办公室完成。无限期



代码(带有非功能代码标签)

[码]


  

#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


[/码]

最佳答案

棘手的解决方案是为OpenOffice进程配备一个监视器。如果您的监视器知道PID并具有特权,则可以每隔几秒钟获取一次CPU时间。如果OO处于停止状态(没有更多的CPU),则监视器可以将其杀死。

解决此问题的最简单方法是让正在打开办公室任务的“包装器”在其运行时对其进行监视,并在其挂起时将其杀死。父进程无论如何都必须等待,因此它也可能需要监视。

如果OpenOffuce挂起一个循环,则很难发现。 CPU通常穿过屋顶,呆在那儿,优先级骤降至最低优先级。处理还是挂?审判电话。您必须让它像这样悬挂一会儿(例如,随机选择一个持续时间,例如432秒(3打打);您总是会second不休。)

10-05 18:20
查看更多