Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-75181

urllib3 gives segfault when in PyQt5 event loop, unless already run before

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.12.1
    • Qt Script
    • None
    • Linux/X11

    Description

      PyQt5 is causing segmention fault when a urllib3 request to read a webpage is made from inside a QApplication event loop.

      The error occurs if, for example, a PyQt5 button-click is used to execute the urllib3 request. The same error occurs if the urllib3 request is run inside the loop without any PyQt5 form being opened. (The same error also occurs with the basic version of urllib, though I have not demonstrated that here).

      Attached routine - test_parse_script.py - shows that this is so. It can be used to run a urrllib3 request outside and inside the PyQt5 event loop, as well as opening a Qt form that runs a urrllib3 request as a button event.

      I can provide more debug info if you would help by instructing me how to get it.

      Below is shown the output of the test routine. It executes a urllib3 request in these different scenarios (and combinations thereof):

      • upon script load
      • during command-line execution of script
      • during command-line execution of script, inside PyQt5 QApplication event loop
      • from within a Qt form, upon button-click
      • upon instantiation of a test class
      • upon execution of a function

      ##  test output ##

       

      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬

      1. read webpage from pyqt5 form

      $ ./test_parse_script.py
      run pre-test?n
      initialise pool manager?n
      run load-test?n
      run QApplication?y
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      RUNNING PYQT5 EVENT LOOP
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      attempt to read webpage now?n
      run func test?n
      run class test?n
      ****************

      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬

      1. run function to read webpage during script loading, then read same webpage from pyqt5 form

      $ ./test_parse_script.py
      run pre-test?y
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      RUNNING PRE-TEST
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      ****************

          • TEST FUNC ***
            ****************
            testing urllib3 poolmanager
            testing urllib3 request
            page status: 200
            page sample: b'<!DOCTYPE html>\n<html lang="en">\n <head>\n'
            run load-test?n
            run QApplication?y
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            RUNNING PYQT5 EVENT LOOP
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            attempt to read webpage now?n
            run func test?n
            run class test?n
            ****************
          • URLS FORM ***
            ****************
            [parse_webpage] testing URL text
            https://www.w3.org/2019/03/pressrelease-webauthn-rec.html.en
            [test_parse] running urllib3 poolmanager
            [parse_url] running urllib3 request
            page status: 200

      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬

      1. upon command-line execution, during pyqt5 event loop, read webpage

      $ ./test_parse_script.py
      run pre-test?n
      initialise pool manager?n
      run load-test?n
      run QApplication?y
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      RUNNING PYQT5 EVENT LOOP
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      attempt to read webpage now?y
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      RUNNING READ WEBPAGE TEST
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      Segmentation fault (core dumped)

      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬

      1. upon command-line execution, during pyqt5 event loop, run function to read webpage

      $ ./test_parse_script.py
      run pre-test?n
      initialise pool manager?n
      run load-test?n
      run QApplication?y
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      RUNNING PYQT5 EVENT LOOP
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      run func test?y
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      RUNNING TEST FUNC
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      ****************

          • TEST FUNC ***
            ****************
            testing urllib3 poolmanager
            testing urllib3 request
            Segmentation fault (core dumped)

      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬

      1. upon command-line execution, during pyqt5 event loop, instantiate class that reads webpage upon init

      $ ./test_parse_script.py
      run pre-test?n
      initialise pool manager?n
      run load-test?n
      run QApplication?y
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      RUNNING PYQT5 EVENT LOOP
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      attempt to read webpage now?n
      run func test?n
      run class test?y
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      RUNNING TEST CLASS
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      ****************

          • URL TEST ***
            ****************
            [URL_TEST] testing urllib3 request
            Segmentation fault (core dumped)

      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬

      1. upon command-line execution, without starting a pyqt5 event loop, read webpage, then run function to read webpage again, and instantiate class that reads webpage upon init

      $ ./test_parse_script.py
      run pre-test?n
      initialise pool manager?n
      run load-test?n
      run QApplication?n
      attempt to read webpage now?y
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      RUNNING READ WEBPAGE TEST
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      page status: 200
      page sample: b'<!DOCTYPE html>\n<html lang="en">\n <head>\n'
      run func test?y
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      RUNNING TEST FUNC
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      ****************

          • TEST FUNC ***
            ****************
            testing urllib3 poolmanager
            testing urllib3 request
            page status: 200
            page sample: b'<!DOCTYPE html>\n<html lang="en">\n <head>\n'
            run class test?y
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            RUNNING TEST CLASS
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            ****************
          • URL TEST ***
            ****************
            [URL_TEST] testing urllib3 request
            page status: 200
            page sample: b'<!DOCTYPE html>\n<html lang="en">\n <head>\n'

      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬

      1. upon script load, run function to read webpage, then upon command-line execution, during pyqt5 event loop, read webpage again, run function to read webpage again, instantiate class that reads webpage upon init, and run pyqt5 form that reads webpage upon button-click

      $ ./test_parse_script.py
      run pre-test?y
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      RUNNING PRE-TEST
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      ****************

          • TEST FUNC ***
            ****************
            testing urllib3 poolmanager
            testing urllib3 request
            page status: 200
            page sample: b'<!DOCTYPE html>\n<html lang="en">\n <head>\n'
            run load-test?n
            run QApplication?y
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            RUNNING PYQT5 EVENT LOOP
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            attempt to read webpage now?y
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            RUNNING READ WEBPAGE TEST
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            page status: 200
            page sample: b'<!DOCTYPE html>\n<html lang="en">\n <head>\n'
            run func test?y
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            RUNNING TEST FUNC
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            ****************
          • TEST FUNC ***
            ****************
            testing urllib3 poolmanager
            testing urllib3 request
            page status: 200
            page sample: b'<!DOCTYPE html>\n<html lang="en">\n <head>\n'
            run class test?y
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            RUNNING TEST CLASS
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            ****************
          • URL TEST ***
            ****************
            [URL_TEST] testing urllib3 request
            page status: 200
            page sample: b'<!DOCTYPE html>\n<html lang="en">\n <head>\n'

      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬

      1. upon script load, setup urllib poolManager, then upon command-line execution, during pyqt5 event loop, read webpage, run function to read webpage again, instantiate class that reads webpage upon init, and run pyqt5 form that reads webpage upon button-click

      $ ./test_parse_script.py
      run pre-test?n
      initialise pool manager?y
      run load-test?n
      run QApplication?y
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      RUNNING PYQT5 EVENT LOOP
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      attempt to read webpage now?y
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      RUNNING READ WEBPAGE TEST
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      Segmentation fault (core dumped)

      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬

      1. upon script load, instantiate class that reads webpage upon init, then upon command-line execution, during pyqt5 event loop, read webpage again, run function to read webpage again, instantiate class that reads webpage upon init, and run pyqt5 form that reads webpage upon button-click

      $ ./test_parse_script.py
      run pre-test?n
      initialise pool manager?n
      run load-test?y
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      RUNNING LOAD TEST
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      ****************

          • URL TEST ***
            ****************
            [URL_TEST] testing urllib3 request
            page status: 200
            page sample: b'<!DOCTYPE html>\n<html lang="en">\n <head>\n'
            run QApplication?y
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            RUNNING PYQT5 EVENT LOOP
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            attempt to read webpage now?y
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            RUNNING READ WEBPAGE TEST
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            page status: 200
            page sample: b'<!DOCTYPE html>\n<html lang="en">\n <head>\n'
            run func test?y
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            RUNNING TEST FUNC
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            ****************
          • TEST FUNC ***
            ****************
            testing urllib3 poolmanager
            testing urllib3 request
            page status: 200
            page sample: b'<!DOCTYPE html>\n<html lang="en">\n <head>\n'
            run class test?y
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            RUNNING TEST CLASS
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            ****************
          • URL TEST ***
            ****************
            [URL_TEST] testing urllib3 request
            page status: 200
            page sample: b'<!DOCTYPE html>\n<html lang="en">\n <head>\n'

      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬

      1. upon script load, run function that reads webpage, then upon command-line execution, during pyqt5 event loop, read different webpage, run function to read webpage again, instantiate class that reads webpage upon init, and run pyqt5 form that reads webpage upon button-click

      $ ./test_parse_script.py
      run pre-test?n
      run alternative pre-test?y
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      RUNNING PRE-TEST
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      ****************

          • TEST FUNC ***
            ****************
            testing urllib3 poolmanager
            testing urllib3 request
            page status: 200
            page sample: b'<!DOCTYPE html>\n<html lang="en">\n <head>\n'
            run load-test?n
            run QApplication?y
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            RUNNING PYQT5 EVENT LOOP
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            attempt to read webpage now?y
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            RUNNING READ WEBPAGE TEST
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            page status: 200
            page sample: b'<!DOCTYPE html>\n<html lang="en">\n <head>\n'
            run func test?y
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            RUNNING TEST FUNC
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            ****************
          • TEST FUNC ***
            ****************
            testing urllib3 poolmanager
            testing urllib3 request
            page status: 200
            page sample: b'<!DOCTYPE html>\n<html lang="en">\n <head>\n'
            run class test?y
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            RUNNING TEST CLASS
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            ****************
          • URL TEST ***
            ****************
            [URL_TEST] testing urllib3 request
            page status: 200
            page sample: b'<!DOCTYPE html>\n<html lang="en">\n <head>\n'
            ****************
          • URLS FORM ***
            ****************
            [parse_webpage] testing URL text
            https://www.w3.org/2019/03/pressrelease-webauthn-rec.html.en
            [test_parse] running urllib3 poolmanager
            [parse_url] running urllib3 request
            page status: 200

      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬

      1. upon script load, run function that reads webpage, then during pyqt5 event loop, run pyqt5 form that reads webpage upon button-click

      $ ./test_parse_script.py
      run pre-test?n
      run alternative pre-test?y
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      RUNNING PRE-TEST
      ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
      ****************

          • TEST FUNC ***
            ****************
            testing urllib3 poolmanager
            testing urllib3 request
            page status: 200
            page sample: b'<!DOCTYPE html>\n<html lang="en">\n <head>\n'
            run load-test?n
            run QApplication?y
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            RUNNING PYQT5 EVENT LOOP
            ¬¬¬¬¬¬¬¬¬¬¬¬¬¬¬
            attempt to read webpage now?n
            run func test?n
            run class test?n
            ****************
          • URLS FORM ***
            ****************
            [parse_webpage] testing URL text
            https://www.w3.org/2019/03/pressrelease-webauthn-rec.html.en
            [test_parse] running urllib3 poolmanager
            [parse_url] running urllib3 request
            page status: 200

       

      Attachments

        1. test_parse_script.py
          6 kB
        2. test_parse.py
          2 kB
        3. test_parse.ui
          2 kB

        Activity

          People

            laknoll Lars Knoll
            mjb Mark Ballard
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: