嗯,我测试了我的 jython 程序,它做了一些简洁的 [".xls"、".doc"、".rtf"、".tif"、".tiff"、".pdf"文件] -> pdf (中间文件)-> 使用 Open Office 进行 tif(最终输出)转换。由于自动化方面存在问题,我们放弃了 MS Office。现在看来我们已经击倒了很多与显示塞子错误有关的瓶子,只剩下一瓶了。一段时间后 OO 挂起。
它发生在你在代码中看到这行“<<<<<<<<<<<<”的地方
我处理停滞的 Open Office 流程的正确方法是什么。您能否提供有用的链接,并给我一个好的出路建议。
还有一个问题。
总结:
* 如何处理停滞的 Open Office 实例?
* 如何使用 java headless 进行转换,这样我就不会一直弹出 GUI 浪费内存。
* 任何有关代码质量、优化和通用编码标准的一般性建议也将不胜感激。
回溯(最内层最后):
文件“dcmail.py”,第 184 行,位于?
文件“dcmail.py”,第 174 行,位于 main
文件“C:\DCMail\digestemails.py”,第 126 行,位于 process_inbox
文件“C:\DCMail\digestemails.py”,第 258 行,位于 _convert
文件“C:\DCMail\digestemails.py”,第 284 行,位于 _choose_conversion_type
文件“C:\DCMail\digestemails.py”,第 287 行,位于 _open_office_convert
文件“C:\DCMail\digestemails.py”,第 299 行,位于 _load_attachment_to_convert
com.sun.star.lang.DisposeException: java.io.EOFException
在 com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge$MessageDi
spacher.run(java_remote_bridge.java:176)
com.sun.star.lang.DisposeException:com.sun.star.lang.DisposeException:java.i o.EOFException
只是为了清除此异常,仅在我终止开放办公进程时抛出。否则程序只会等待 open office 完成。无限期
<小时/>代码(带有非功能代码标签)
[代码]
block 引用>#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 打);你总是会怀疑自己。)
关于java - loadComponentFromURL 摔倒身亡,如何进行心肺复苏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/301239/