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")
    try:
        QApplication(sys.argv + ['-platform', 'offscreen'])
    except Exception as err:
        print("oops", err)

    print("Sleeping now...")
    time.sleep(10)

if __name__ == "__main__":
    proc = multiprocessing.Process(target=test_wait)
    proc.start()
    proc.join()
    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()
    proc.start()
    proc.join()

    # 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 :(")
    else:
        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

_______________________________________________
PySide mailing list
PySide@qt-project.org
https://lists.qt-project.org/listinfo/pyside

Reply via email to