title: ERROR:network_service_instance_impl.cc(262)] Network service crashed, restarting service. Pyqt5 error when python compiled to executable only. Windows
body: <p>So I have developed a tool in which part of it involves converting large, local (x)html files into pdf. To do so I use PyQt5. Having neared the end of version 1, I am trying to compile my tool into a .exe file so that it can be distributed to my team without them all needing to download python/anaconda and all the required packages.</p>
  <p>Issue is when I convert the python files to .exe files the html to pdf conversion no longer works. I believe it has something to do with the sys.argv argument in the QApplication instantiation but I haven't been able to figure out the correct way of doing this in an executable file.</p>
  <p>I have segmented the python code from the tool and tried converting it as a stand alone and it still doesn't work, below is the python file, the output from running html_to_pdf.py file in the terminal, the spec file used with pyinstaller and the output from the html_to_pdf.exe run from the terminal. As you can see the python file complies and the executable doesn't with the repeating error which can only be stopped by closing the entire terminal (Ctrl+C doesn't work).</p>
  <p>Versions</p>
  <ul>
  <li>Windows 10 Enterprise</li>
  <li>Anaconda 4.10.1</li>
  <li>Pyqt5 5.15.4</li>
  <li>PyQtWebEngine 5.15.4</li>
  <li>PyQt5-sip 12.9.0</li>
  </ul>
  <p><strong>html_to_pdf.py</strong></p>
  <pre><code>from PyQt5.QtCore import QCoreApplication
  from PyQt5 import QtCore, QtWidgets
  from PyQt5 import QtWebEngineWidgets
  import os
  import sys
  
  Name = 'large'
  updated_html_path = os.getcwd()+'/large.html'
  
  html_pdf = os.getcwd()+'/'+Name+'.pdf'
  print('checking if there is already an app')
  
  app = QCoreApplication.instance()
  print('checking for app', app)
  
  if app is None:
      print('making a new app')
      print(sys.argv)
      # print(sys.arg)
      app = QApplication(sys.argv)
  print('app', app)
  
  page = QtWebEngineWidgets.QWebEnginePage()
  print('page', page)
  
  def handle_print_finished(filename, status):
      print(&quot;finished&quot;, filename, status)
      QtWidgets.QApplication.quit()
  def handle_load_finished(status):
      if status:
          print('page printing to pdf')
          page.printToPdf(html_pdf)
      else:
          print(&quot;Failed&quot;)
          QtWidgets.QApplication.quit()
  print('before starting the conversion')
  
  page.pdfPrintingFinished.connect(handle_print_finished)
  print('post step 1')      
  
  page.loadFinished.connect(handle_load_finished)
  print('post step 2')
  
  page.load(QtCore.QUrl.fromLocalFile(updated_html_path))
  print('post step 3')
  
  app.exec_()
  print('post executed')
  
  app.quit()
  print('post quit')
  </code></pre>
  <p><strong>output from html_to_pdf.py run in the terminal:</strong></p>
  <pre><code>checking if there is already an app
  checking for app None
  making a new app
  ['html_to_pdf.py']
  app &lt;PyQt5.QtWidgets.QApplication object at 0x000001D9E9A5D160&gt;
  page &lt;PyQt5.QtWebEngineWidgets.QWebEnginePage object at 0x000001D9EA01EDC0&gt;
  before starting the conversion
  post step 1
  post step 2
  post step 3
  page printing to pdf
  finished C:\Users\amackay012\Documents\CMAS\Stack html2pdf/large.pdf True
  post executed
  post quit
  </code></pre>
  <p><strong>html_to_pdf.spec</strong></p>
  <pre><code>block_cipher = None
  
  a = Analysis(['html_to_pdf.py'],
               pathex=['C:\\Users\\amackay012\\Documents\\CMAS\\Stack html2pdf'],
               binaries=[],
               datas=[],
               hiddenimports=['PyQtWebEngine'],
               hookspath=[],
               runtime_hooks=[],
               excludes=[],
               win_no_prefer_redirects=False,
               win_private_assemblies=False,
               cipher=block_cipher,
               noarchive=False)
  pyz = PYZ(a.pure, a.zipped_data,
               cipher=block_cipher)
  
  for data in a.datas:
      if 'QtWebEngineProcess.exe' in data[0]:
          a.datas[a.datas.index(data)] = (u'PyQt5\\Qt5\\bin\\'+data[0].split('\\')[-1], data[1], data[2])
          
      if 'Qt\\resources' in data[0]:
          a.datas[a.datas.index(data)] = (u'PyQt5\\Qt5\\resources\\'+data[0].split('resources\\')[-1], data[1], data[2])
          
      if 'Qt\\translations' in data[0]:
          print('inside translations if')
          a.datas[a.datas.index(data)] = (u'PyQt5\\Qt5\\translations\\'+data[0].split('translations\\')[-1], data[1], data[2])
  
  exe = EXE(pyz,
            a.scripts,
            [],
            exclude_binaries=True,
            name='html_to_pdf',
            debug=False,
            bootloader_ignore_signals=False,
            strip=False,
            upx=True,
            console=True )
  coll = COLLECT(exe,
                 a.binaries,
                 a.zipfiles,
                 a.datas,
                 strip=False,
                 upx=True,
                 upx_exclude=[],
                 name='html_to_pdf')
  </code></pre>
  <p>There was an issue with the pyqt files being in the wrong folder so I added the for loop to the spec file to fix that.</p>
  <p><strong>Output from running html_to_pdf.exe in terminal:</strong></p>
  <pre><code>checking if there is already an app
  checking for app None
  making a new app
  ['html_to_pdf.exe']
  app &lt;PyQt5.QtWidgets.QApplication object at 0x00000292D8EB60D0&gt;
  page &lt;PyQt5.QtWebEngineWidgets.QWebEnginePage object at 0x00000292D8EB6040&gt;
  before starting the conversion
  post step 1
  post step 2
  post step 3
  [23680:13060:0709/112612.676:ERROR:network_service_instance_impl.cc(262)] Network service crashed, restarting service.
  [23680:13060:0709/112613.857:ERROR:network_service_instance_impl.cc(262)] Network service crashed, restarting service.
  [23680:13060:0709/112614.965:ERROR:network_service_instance_impl.cc(262)] Network service crashed, restarting service.
  [23680:13060:0709/112616.078:ERROR:network_service_instance_impl.cc(262)] Network service crashed, restarting service.
  [23680:13060:0709/112617.520:ERROR:network_service_instance_impl.cc(262)] Network service crashed, restarting service.
  [23680:13060:0709/112618.794:ERROR:network_service_instance_impl.cc(262)] Network service crashed, restarting service.
  [23680:13060:0709/112619.930:ERROR:network_service_instance_impl.cc(262)] Network service crashed, restarting service.
  </code></pre>
  <p>I am aware this is a common error however I have only been able to find solutions for Linux versions of the tool installed in github or a lot of reference to qutebrowser which I'm not sure i have? <a href="https://github.com/qutebrowser/qutebrowser/issues/6235" rel="nofollow noreferrer">https://github.com/qutebrowser/qutebrowser/issues/6235</a></p>
  <p>I also noticed that my error has (262) rather than (286).</p>