[PySide] PySide2 + multiprocessing + requests = crash?

Israel Brewster ijbrewster at alaska.edu
Tue Dec 17 19:13:51 CET 2019

I’ve found what seems to be an odd crash to me. Using PySide2 and multiprocessing works fine to create a QAppliction in a separate process (unless this is considered bad form?) - unless I call requests.get at some point before starting said process, in which case the process crashes (hard crash, not python exception). How might I fix this?

A little background: I’m using Qt classes to generate a bunch of images from data files. To speed things along, I launch a process (using multiprocessing.Process) for each image I want to generate, and in each process I create a QApplication, create and fill the widgets I need for the image, and then save the image to a file. This appears to work fine, creating the images in parallel. Today I tried to do a requests call before doing any of the processing (simple get, doesn’t interact with QT in any way), and suddenly my code started crashing.

Some simplified sample code that illustrates the issue:

import time
import multiprocessing
import sys
from PySide2.QtWidgets import QApplication
import requests

def test_wait():
    print("Starting proc")
        QApplication(sys.argv + ['-platform', 'offscreen'])
    except Exception as err:
        print("oops", err)

    print("Sleeping now...")

if __name__ == "__main__":
    proc = multiprocessing.Process(target=test_wait)
    print("Awake again. Let's try another:")

    res = requests.get('https://www.google.com')  # or whatever your favorite is
    res.text  # Get the response, close it out

    proc = multiprocessing.Process(target=test_wait)
    start = time.time()

    # The process should sleep for 10 seconds, so if we got here in less than 9, we died.
    if time.time() - start < 9:
        print("Never slept :(")
        print("We lived!")

Israel Brewster
Software Engineer
Alaska Volcano Observatory 
Geophysical Institute - UAF 
2156 Koyukuk Drive 
Fairbanks AK 99775-7320
Work: 907-474-5172
cell:  907-328-9145

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20191217/3441cf38/attachment.html>

More information about the PySide mailing list