PyQt5 looping issue, only last iteration of QWebEngineView object works










1















I have no prior experience with Qt/PyQt.
I'm just trying to use PyQt for the web engine capabilities, to 'convert' a folder of html files to pdf documents.



The code works well if there is only 1 html file, but when there are multiple html files it only generates a pdf for the last file in the loop.



I think the issue must be to do with Qt stuff, looping, events etc - but I have no idea where to begin to sort this out. As you can tell I'm only Qt to produce html->pdf, I'm not interested in building a GUI.



I read about using QApplication.processEvents() at the end of the loop may fix this, but the result was the same.
I tried adding a sleep/pause to the code, also the same.



import sys
import os

from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtCore import QDir, QUrl

# read somewhere this is needed to load local html, works without for me though
sys.argv.append("--disable-web-security")
app = QApplication(sys.argv)

iter_num = 0

directory = 'my_webfile_directory'
for filename in os.listdir(directory):
if filename.endswith(".htm") or filename.endswith(".html"):
with open(os.path.join(directory, filename), 'r') as myfile:

print(filename)
raw_html = myfile.read()
# init qt web view
view = QWebEngineView()
view.setHtml(raw_html)

# set to close web view after pdf is created
view.page().pdfPrintingFinished.connect(view.close)
# generate filename
iter_num += 1
outputfilename = str(iter_num) + ".pdf"
outputfullpath = os.path.join(directory, outputfilename)

def save_pdf(finished):
view.page().printToPdf(outputfullpath)
# when web view is ready, save the pdf
view.loadFinished.connect(save_pdf)
# QApplication.processEvents()

app.exec()









share|improve this question


























    1















    I have no prior experience with Qt/PyQt.
    I'm just trying to use PyQt for the web engine capabilities, to 'convert' a folder of html files to pdf documents.



    The code works well if there is only 1 html file, but when there are multiple html files it only generates a pdf for the last file in the loop.



    I think the issue must be to do with Qt stuff, looping, events etc - but I have no idea where to begin to sort this out. As you can tell I'm only Qt to produce html->pdf, I'm not interested in building a GUI.



    I read about using QApplication.processEvents() at the end of the loop may fix this, but the result was the same.
    I tried adding a sleep/pause to the code, also the same.



    import sys
    import os

    from PyQt5.QtWidgets import QApplication
    from PyQt5.QtWebEngineWidgets import QWebEngineView
    from PyQt5.QtCore import QDir, QUrl

    # read somewhere this is needed to load local html, works without for me though
    sys.argv.append("--disable-web-security")
    app = QApplication(sys.argv)

    iter_num = 0

    directory = 'my_webfile_directory'
    for filename in os.listdir(directory):
    if filename.endswith(".htm") or filename.endswith(".html"):
    with open(os.path.join(directory, filename), 'r') as myfile:

    print(filename)
    raw_html = myfile.read()
    # init qt web view
    view = QWebEngineView()
    view.setHtml(raw_html)

    # set to close web view after pdf is created
    view.page().pdfPrintingFinished.connect(view.close)
    # generate filename
    iter_num += 1
    outputfilename = str(iter_num) + ".pdf"
    outputfullpath = os.path.join(directory, outputfilename)

    def save_pdf(finished):
    view.page().printToPdf(outputfullpath)
    # when web view is ready, save the pdf
    view.loadFinished.connect(save_pdf)
    # QApplication.processEvents()

    app.exec()









    share|improve this question
























      1












      1








      1








      I have no prior experience with Qt/PyQt.
      I'm just trying to use PyQt for the web engine capabilities, to 'convert' a folder of html files to pdf documents.



      The code works well if there is only 1 html file, but when there are multiple html files it only generates a pdf for the last file in the loop.



      I think the issue must be to do with Qt stuff, looping, events etc - but I have no idea where to begin to sort this out. As you can tell I'm only Qt to produce html->pdf, I'm not interested in building a GUI.



      I read about using QApplication.processEvents() at the end of the loop may fix this, but the result was the same.
      I tried adding a sleep/pause to the code, also the same.



      import sys
      import os

      from PyQt5.QtWidgets import QApplication
      from PyQt5.QtWebEngineWidgets import QWebEngineView
      from PyQt5.QtCore import QDir, QUrl

      # read somewhere this is needed to load local html, works without for me though
      sys.argv.append("--disable-web-security")
      app = QApplication(sys.argv)

      iter_num = 0

      directory = 'my_webfile_directory'
      for filename in os.listdir(directory):
      if filename.endswith(".htm") or filename.endswith(".html"):
      with open(os.path.join(directory, filename), 'r') as myfile:

      print(filename)
      raw_html = myfile.read()
      # init qt web view
      view = QWebEngineView()
      view.setHtml(raw_html)

      # set to close web view after pdf is created
      view.page().pdfPrintingFinished.connect(view.close)
      # generate filename
      iter_num += 1
      outputfilename = str(iter_num) + ".pdf"
      outputfullpath = os.path.join(directory, outputfilename)

      def save_pdf(finished):
      view.page().printToPdf(outputfullpath)
      # when web view is ready, save the pdf
      view.loadFinished.connect(save_pdf)
      # QApplication.processEvents()

      app.exec()









      share|improve this question














      I have no prior experience with Qt/PyQt.
      I'm just trying to use PyQt for the web engine capabilities, to 'convert' a folder of html files to pdf documents.



      The code works well if there is only 1 html file, but when there are multiple html files it only generates a pdf for the last file in the loop.



      I think the issue must be to do with Qt stuff, looping, events etc - but I have no idea where to begin to sort this out. As you can tell I'm only Qt to produce html->pdf, I'm not interested in building a GUI.



      I read about using QApplication.processEvents() at the end of the loop may fix this, but the result was the same.
      I tried adding a sleep/pause to the code, also the same.



      import sys
      import os

      from PyQt5.QtWidgets import QApplication
      from PyQt5.QtWebEngineWidgets import QWebEngineView
      from PyQt5.QtCore import QDir, QUrl

      # read somewhere this is needed to load local html, works without for me though
      sys.argv.append("--disable-web-security")
      app = QApplication(sys.argv)

      iter_num = 0

      directory = 'my_webfile_directory'
      for filename in os.listdir(directory):
      if filename.endswith(".htm") or filename.endswith(".html"):
      with open(os.path.join(directory, filename), 'r') as myfile:

      print(filename)
      raw_html = myfile.read()
      # init qt web view
      view = QWebEngineView()
      view.setHtml(raw_html)

      # set to close web view after pdf is created
      view.page().pdfPrintingFinished.connect(view.close)
      # generate filename
      iter_num += 1
      outputfilename = str(iter_num) + ".pdf"
      outputfullpath = os.path.join(directory, outputfilename)

      def save_pdf(finished):
      view.page().printToPdf(outputfullpath)
      # when web view is ready, save the pdf
      view.loadFinished.connect(save_pdf)
      # QApplication.processEvents()

      app.exec()






      python pyqt pyqt5






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 9:38









      Ben Kailon Ben Kailon

      846




      846






















          1 Answer
          1






          active

          oldest

          votes


















          1














          I think QWebEngineView is not thread-safe because I was able to make it work consistently by creating a queue of files to be processed and executing one after the other using a signal, here is a demo application:



          import sys
          import os

          from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox
          from PyQt5.QtWebEngineWidgets import QWebEngineView
          from PyQt5.QtCore import QObject, QDir, QUrl, pyqtSignal


          class HtmlToPdfConverter(QObject):

          queueProcessed = pyqtSignal()

          def __init__(self):
          super().__init__()

          self._queue =
          self._current = None

          def queue(self, html_file, output_file):
          self._queue.append((html_file, output_file))

          def process_queue(self):
          if self._queue:
          raw_html = ''
          self._current = self._queue.pop(0)
          with open(self._current[0], 'r') as my_file:
          raw_html = my_file.read()

          view = QWebEngineView()
          view.loadFinished.connect(self._get_load_finished_event(view))
          view.page().pdfPrintingFinished.connect(self._get_printing_finished_event(view))
          view.setHtml(raw_html)
          else:
          self.queueProcessed.emit()

          def _get_load_finished_event(self, view):
          def _load_finished(success):
          if success:
          view.page().printToPdf(self._current[1])
          return _load_finished

          def _get_printing_finished_event(self, view):
          def _printing_finished(file, success):
          view.close()
          self.process_queue()
          return _printing_finished


          class App(QApplication):
          def __init__(self, sys_argv):
          super().__init__(sys_argv)

          self.dummy_window = QMainWindow()
          self.dummy_window.show()

          def generate_pdfs(self, directory):
          converter = HtmlToPdfConverter()
          converter.queueProcessed.connect(self._queue_processed)

          iter_num = 0

          for filename in os.listdir(directory):
          if filename.endswith(".htm") or filename.endswith(".html"):
          iter_num += 1
          out_filename = os.path.join(directory, str(iter_num) + ".pdf")
          converter.queue(os.path.join(directory, filename), out_filename)

          converter.process_queue()

          def _queue_processed(self):
          QMessageBox.information(self.dummy_window, 'Pdf Generator', 'All PDF files have been generated.')


          if __name__ == '__main__':
          app = App(sys.argv)
          app.generate_pdfs('c:/temp/test')

          sys.exit(app.exec_())





          share|improve this answer

























          • I appreciate your help, but using your code, at least for me - in a folder of 3 html files, only the 2nd PDF gets generated. - edit. It's not consistent. Sometimes I get only 1 pdf file, sometimes 2, sometimes all 3. All 3 html files are identical in my testing.

            –  Ben Kailon
            Nov 14 '18 at 8:38












          • Just simple HTML - pastebin.com/FTqiTmQJ win32. When using 3 identical html files, usually only 1 or 2 pdfs are generated. But no errors in command line. But when using 7 of these html files, and running using command prompt (not within VS Code) now I get more information about about the errors: [764:6240:1114/095012.944:ERROR:broker_win.cc(59)] Error reading broker pipe: The pipe has been ended. (0x6D) [764:6240:1114/095012.947:ERROR:print_web_view_helper.cc(1579)] I get a many of these errors printed after the final html file names is printed. Very strange Thanks

            –  Ben Kailon
            Nov 14 '18 at 9:52







          • 1





            I was able to reproduce it, I will try to find a solution.

            – Isma
            Nov 14 '18 at 9:59











          • Thank you for the help. I can confirm this happens on win64 pyqt 5.11, and win32 pyqt 5.10.

            –  Ben Kailon
            Nov 14 '18 at 10:31






          • 1





            Check the updated answer... Hopefully it will work now.

            – Isma
            Nov 14 '18 at 11:15










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53277956%2fpyqt5-looping-issue-only-last-iteration-of-qwebengineview-object-works%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          I think QWebEngineView is not thread-safe because I was able to make it work consistently by creating a queue of files to be processed and executing one after the other using a signal, here is a demo application:



          import sys
          import os

          from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox
          from PyQt5.QtWebEngineWidgets import QWebEngineView
          from PyQt5.QtCore import QObject, QDir, QUrl, pyqtSignal


          class HtmlToPdfConverter(QObject):

          queueProcessed = pyqtSignal()

          def __init__(self):
          super().__init__()

          self._queue =
          self._current = None

          def queue(self, html_file, output_file):
          self._queue.append((html_file, output_file))

          def process_queue(self):
          if self._queue:
          raw_html = ''
          self._current = self._queue.pop(0)
          with open(self._current[0], 'r') as my_file:
          raw_html = my_file.read()

          view = QWebEngineView()
          view.loadFinished.connect(self._get_load_finished_event(view))
          view.page().pdfPrintingFinished.connect(self._get_printing_finished_event(view))
          view.setHtml(raw_html)
          else:
          self.queueProcessed.emit()

          def _get_load_finished_event(self, view):
          def _load_finished(success):
          if success:
          view.page().printToPdf(self._current[1])
          return _load_finished

          def _get_printing_finished_event(self, view):
          def _printing_finished(file, success):
          view.close()
          self.process_queue()
          return _printing_finished


          class App(QApplication):
          def __init__(self, sys_argv):
          super().__init__(sys_argv)

          self.dummy_window = QMainWindow()
          self.dummy_window.show()

          def generate_pdfs(self, directory):
          converter = HtmlToPdfConverter()
          converter.queueProcessed.connect(self._queue_processed)

          iter_num = 0

          for filename in os.listdir(directory):
          if filename.endswith(".htm") or filename.endswith(".html"):
          iter_num += 1
          out_filename = os.path.join(directory, str(iter_num) + ".pdf")
          converter.queue(os.path.join(directory, filename), out_filename)

          converter.process_queue()

          def _queue_processed(self):
          QMessageBox.information(self.dummy_window, 'Pdf Generator', 'All PDF files have been generated.')


          if __name__ == '__main__':
          app = App(sys.argv)
          app.generate_pdfs('c:/temp/test')

          sys.exit(app.exec_())





          share|improve this answer

























          • I appreciate your help, but using your code, at least for me - in a folder of 3 html files, only the 2nd PDF gets generated. - edit. It's not consistent. Sometimes I get only 1 pdf file, sometimes 2, sometimes all 3. All 3 html files are identical in my testing.

            –  Ben Kailon
            Nov 14 '18 at 8:38












          • Just simple HTML - pastebin.com/FTqiTmQJ win32. When using 3 identical html files, usually only 1 or 2 pdfs are generated. But no errors in command line. But when using 7 of these html files, and running using command prompt (not within VS Code) now I get more information about about the errors: [764:6240:1114/095012.944:ERROR:broker_win.cc(59)] Error reading broker pipe: The pipe has been ended. (0x6D) [764:6240:1114/095012.947:ERROR:print_web_view_helper.cc(1579)] I get a many of these errors printed after the final html file names is printed. Very strange Thanks

            –  Ben Kailon
            Nov 14 '18 at 9:52







          • 1





            I was able to reproduce it, I will try to find a solution.

            – Isma
            Nov 14 '18 at 9:59











          • Thank you for the help. I can confirm this happens on win64 pyqt 5.11, and win32 pyqt 5.10.

            –  Ben Kailon
            Nov 14 '18 at 10:31






          • 1





            Check the updated answer... Hopefully it will work now.

            – Isma
            Nov 14 '18 at 11:15















          1














          I think QWebEngineView is not thread-safe because I was able to make it work consistently by creating a queue of files to be processed and executing one after the other using a signal, here is a demo application:



          import sys
          import os

          from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox
          from PyQt5.QtWebEngineWidgets import QWebEngineView
          from PyQt5.QtCore import QObject, QDir, QUrl, pyqtSignal


          class HtmlToPdfConverter(QObject):

          queueProcessed = pyqtSignal()

          def __init__(self):
          super().__init__()

          self._queue =
          self._current = None

          def queue(self, html_file, output_file):
          self._queue.append((html_file, output_file))

          def process_queue(self):
          if self._queue:
          raw_html = ''
          self._current = self._queue.pop(0)
          with open(self._current[0], 'r') as my_file:
          raw_html = my_file.read()

          view = QWebEngineView()
          view.loadFinished.connect(self._get_load_finished_event(view))
          view.page().pdfPrintingFinished.connect(self._get_printing_finished_event(view))
          view.setHtml(raw_html)
          else:
          self.queueProcessed.emit()

          def _get_load_finished_event(self, view):
          def _load_finished(success):
          if success:
          view.page().printToPdf(self._current[1])
          return _load_finished

          def _get_printing_finished_event(self, view):
          def _printing_finished(file, success):
          view.close()
          self.process_queue()
          return _printing_finished


          class App(QApplication):
          def __init__(self, sys_argv):
          super().__init__(sys_argv)

          self.dummy_window = QMainWindow()
          self.dummy_window.show()

          def generate_pdfs(self, directory):
          converter = HtmlToPdfConverter()
          converter.queueProcessed.connect(self._queue_processed)

          iter_num = 0

          for filename in os.listdir(directory):
          if filename.endswith(".htm") or filename.endswith(".html"):
          iter_num += 1
          out_filename = os.path.join(directory, str(iter_num) + ".pdf")
          converter.queue(os.path.join(directory, filename), out_filename)

          converter.process_queue()

          def _queue_processed(self):
          QMessageBox.information(self.dummy_window, 'Pdf Generator', 'All PDF files have been generated.')


          if __name__ == '__main__':
          app = App(sys.argv)
          app.generate_pdfs('c:/temp/test')

          sys.exit(app.exec_())





          share|improve this answer

























          • I appreciate your help, but using your code, at least for me - in a folder of 3 html files, only the 2nd PDF gets generated. - edit. It's not consistent. Sometimes I get only 1 pdf file, sometimes 2, sometimes all 3. All 3 html files are identical in my testing.

            –  Ben Kailon
            Nov 14 '18 at 8:38












          • Just simple HTML - pastebin.com/FTqiTmQJ win32. When using 3 identical html files, usually only 1 or 2 pdfs are generated. But no errors in command line. But when using 7 of these html files, and running using command prompt (not within VS Code) now I get more information about about the errors: [764:6240:1114/095012.944:ERROR:broker_win.cc(59)] Error reading broker pipe: The pipe has been ended. (0x6D) [764:6240:1114/095012.947:ERROR:print_web_view_helper.cc(1579)] I get a many of these errors printed after the final html file names is printed. Very strange Thanks

            –  Ben Kailon
            Nov 14 '18 at 9:52







          • 1





            I was able to reproduce it, I will try to find a solution.

            – Isma
            Nov 14 '18 at 9:59











          • Thank you for the help. I can confirm this happens on win64 pyqt 5.11, and win32 pyqt 5.10.

            –  Ben Kailon
            Nov 14 '18 at 10:31






          • 1





            Check the updated answer... Hopefully it will work now.

            – Isma
            Nov 14 '18 at 11:15













          1












          1








          1







          I think QWebEngineView is not thread-safe because I was able to make it work consistently by creating a queue of files to be processed and executing one after the other using a signal, here is a demo application:



          import sys
          import os

          from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox
          from PyQt5.QtWebEngineWidgets import QWebEngineView
          from PyQt5.QtCore import QObject, QDir, QUrl, pyqtSignal


          class HtmlToPdfConverter(QObject):

          queueProcessed = pyqtSignal()

          def __init__(self):
          super().__init__()

          self._queue =
          self._current = None

          def queue(self, html_file, output_file):
          self._queue.append((html_file, output_file))

          def process_queue(self):
          if self._queue:
          raw_html = ''
          self._current = self._queue.pop(0)
          with open(self._current[0], 'r') as my_file:
          raw_html = my_file.read()

          view = QWebEngineView()
          view.loadFinished.connect(self._get_load_finished_event(view))
          view.page().pdfPrintingFinished.connect(self._get_printing_finished_event(view))
          view.setHtml(raw_html)
          else:
          self.queueProcessed.emit()

          def _get_load_finished_event(self, view):
          def _load_finished(success):
          if success:
          view.page().printToPdf(self._current[1])
          return _load_finished

          def _get_printing_finished_event(self, view):
          def _printing_finished(file, success):
          view.close()
          self.process_queue()
          return _printing_finished


          class App(QApplication):
          def __init__(self, sys_argv):
          super().__init__(sys_argv)

          self.dummy_window = QMainWindow()
          self.dummy_window.show()

          def generate_pdfs(self, directory):
          converter = HtmlToPdfConverter()
          converter.queueProcessed.connect(self._queue_processed)

          iter_num = 0

          for filename in os.listdir(directory):
          if filename.endswith(".htm") or filename.endswith(".html"):
          iter_num += 1
          out_filename = os.path.join(directory, str(iter_num) + ".pdf")
          converter.queue(os.path.join(directory, filename), out_filename)

          converter.process_queue()

          def _queue_processed(self):
          QMessageBox.information(self.dummy_window, 'Pdf Generator', 'All PDF files have been generated.')


          if __name__ == '__main__':
          app = App(sys.argv)
          app.generate_pdfs('c:/temp/test')

          sys.exit(app.exec_())





          share|improve this answer















          I think QWebEngineView is not thread-safe because I was able to make it work consistently by creating a queue of files to be processed and executing one after the other using a signal, here is a demo application:



          import sys
          import os

          from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox
          from PyQt5.QtWebEngineWidgets import QWebEngineView
          from PyQt5.QtCore import QObject, QDir, QUrl, pyqtSignal


          class HtmlToPdfConverter(QObject):

          queueProcessed = pyqtSignal()

          def __init__(self):
          super().__init__()

          self._queue =
          self._current = None

          def queue(self, html_file, output_file):
          self._queue.append((html_file, output_file))

          def process_queue(self):
          if self._queue:
          raw_html = ''
          self._current = self._queue.pop(0)
          with open(self._current[0], 'r') as my_file:
          raw_html = my_file.read()

          view = QWebEngineView()
          view.loadFinished.connect(self._get_load_finished_event(view))
          view.page().pdfPrintingFinished.connect(self._get_printing_finished_event(view))
          view.setHtml(raw_html)
          else:
          self.queueProcessed.emit()

          def _get_load_finished_event(self, view):
          def _load_finished(success):
          if success:
          view.page().printToPdf(self._current[1])
          return _load_finished

          def _get_printing_finished_event(self, view):
          def _printing_finished(file, success):
          view.close()
          self.process_queue()
          return _printing_finished


          class App(QApplication):
          def __init__(self, sys_argv):
          super().__init__(sys_argv)

          self.dummy_window = QMainWindow()
          self.dummy_window.show()

          def generate_pdfs(self, directory):
          converter = HtmlToPdfConverter()
          converter.queueProcessed.connect(self._queue_processed)

          iter_num = 0

          for filename in os.listdir(directory):
          if filename.endswith(".htm") or filename.endswith(".html"):
          iter_num += 1
          out_filename = os.path.join(directory, str(iter_num) + ".pdf")
          converter.queue(os.path.join(directory, filename), out_filename)

          converter.process_queue()

          def _queue_processed(self):
          QMessageBox.information(self.dummy_window, 'Pdf Generator', 'All PDF files have been generated.')


          if __name__ == '__main__':
          app = App(sys.argv)
          app.generate_pdfs('c:/temp/test')

          sys.exit(app.exec_())






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 14 '18 at 11:30

























          answered Nov 13 '18 at 10:52









          IsmaIsma

          7,95342036




          7,95342036












          • I appreciate your help, but using your code, at least for me - in a folder of 3 html files, only the 2nd PDF gets generated. - edit. It's not consistent. Sometimes I get only 1 pdf file, sometimes 2, sometimes all 3. All 3 html files are identical in my testing.

            –  Ben Kailon
            Nov 14 '18 at 8:38












          • Just simple HTML - pastebin.com/FTqiTmQJ win32. When using 3 identical html files, usually only 1 or 2 pdfs are generated. But no errors in command line. But when using 7 of these html files, and running using command prompt (not within VS Code) now I get more information about about the errors: [764:6240:1114/095012.944:ERROR:broker_win.cc(59)] Error reading broker pipe: The pipe has been ended. (0x6D) [764:6240:1114/095012.947:ERROR:print_web_view_helper.cc(1579)] I get a many of these errors printed after the final html file names is printed. Very strange Thanks

            –  Ben Kailon
            Nov 14 '18 at 9:52







          • 1





            I was able to reproduce it, I will try to find a solution.

            – Isma
            Nov 14 '18 at 9:59











          • Thank you for the help. I can confirm this happens on win64 pyqt 5.11, and win32 pyqt 5.10.

            –  Ben Kailon
            Nov 14 '18 at 10:31






          • 1





            Check the updated answer... Hopefully it will work now.

            – Isma
            Nov 14 '18 at 11:15

















          • I appreciate your help, but using your code, at least for me - in a folder of 3 html files, only the 2nd PDF gets generated. - edit. It's not consistent. Sometimes I get only 1 pdf file, sometimes 2, sometimes all 3. All 3 html files are identical in my testing.

            –  Ben Kailon
            Nov 14 '18 at 8:38












          • Just simple HTML - pastebin.com/FTqiTmQJ win32. When using 3 identical html files, usually only 1 or 2 pdfs are generated. But no errors in command line. But when using 7 of these html files, and running using command prompt (not within VS Code) now I get more information about about the errors: [764:6240:1114/095012.944:ERROR:broker_win.cc(59)] Error reading broker pipe: The pipe has been ended. (0x6D) [764:6240:1114/095012.947:ERROR:print_web_view_helper.cc(1579)] I get a many of these errors printed after the final html file names is printed. Very strange Thanks

            –  Ben Kailon
            Nov 14 '18 at 9:52







          • 1





            I was able to reproduce it, I will try to find a solution.

            – Isma
            Nov 14 '18 at 9:59











          • Thank you for the help. I can confirm this happens on win64 pyqt 5.11, and win32 pyqt 5.10.

            –  Ben Kailon
            Nov 14 '18 at 10:31






          • 1





            Check the updated answer... Hopefully it will work now.

            – Isma
            Nov 14 '18 at 11:15
















          I appreciate your help, but using your code, at least for me - in a folder of 3 html files, only the 2nd PDF gets generated. - edit. It's not consistent. Sometimes I get only 1 pdf file, sometimes 2, sometimes all 3. All 3 html files are identical in my testing.

          –  Ben Kailon
          Nov 14 '18 at 8:38






          I appreciate your help, but using your code, at least for me - in a folder of 3 html files, only the 2nd PDF gets generated. - edit. It's not consistent. Sometimes I get only 1 pdf file, sometimes 2, sometimes all 3. All 3 html files are identical in my testing.

          –  Ben Kailon
          Nov 14 '18 at 8:38














          Just simple HTML - pastebin.com/FTqiTmQJ win32. When using 3 identical html files, usually only 1 or 2 pdfs are generated. But no errors in command line. But when using 7 of these html files, and running using command prompt (not within VS Code) now I get more information about about the errors: [764:6240:1114/095012.944:ERROR:broker_win.cc(59)] Error reading broker pipe: The pipe has been ended. (0x6D) [764:6240:1114/095012.947:ERROR:print_web_view_helper.cc(1579)] I get a many of these errors printed after the final html file names is printed. Very strange Thanks

          –  Ben Kailon
          Nov 14 '18 at 9:52






          Just simple HTML - pastebin.com/FTqiTmQJ win32. When using 3 identical html files, usually only 1 or 2 pdfs are generated. But no errors in command line. But when using 7 of these html files, and running using command prompt (not within VS Code) now I get more information about about the errors: [764:6240:1114/095012.944:ERROR:broker_win.cc(59)] Error reading broker pipe: The pipe has been ended. (0x6D) [764:6240:1114/095012.947:ERROR:print_web_view_helper.cc(1579)] I get a many of these errors printed after the final html file names is printed. Very strange Thanks

          –  Ben Kailon
          Nov 14 '18 at 9:52





          1




          1





          I was able to reproduce it, I will try to find a solution.

          – Isma
          Nov 14 '18 at 9:59





          I was able to reproduce it, I will try to find a solution.

          – Isma
          Nov 14 '18 at 9:59













          Thank you for the help. I can confirm this happens on win64 pyqt 5.11, and win32 pyqt 5.10.

          –  Ben Kailon
          Nov 14 '18 at 10:31





          Thank you for the help. I can confirm this happens on win64 pyqt 5.11, and win32 pyqt 5.10.

          –  Ben Kailon
          Nov 14 '18 at 10:31




          1




          1





          Check the updated answer... Hopefully it will work now.

          – Isma
          Nov 14 '18 at 11:15





          Check the updated answer... Hopefully it will work now.

          – Isma
          Nov 14 '18 at 11:15



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53277956%2fpyqt5-looping-issue-only-last-iteration-of-qwebengineview-object-works%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Use pre created SQLite database for Android project in kotlin

          Darth Vader #20

          Ondo