Use a local event-loop to wait until the window/widget closes:
widget = QWidget()
widget.setAttribute(Qt.WA_DeleteOnClose)
widget.show()
loop = QEventLoop()
widget.destroyed.connect(loop.quit)
loop.exec() # wait ...
print('finished')
To also block interaction with other windows, set the window modality:
widget.setWindowModality(Qt.ApplicationModal)
or for top-level windows with a parent:
window.setWindowModality(Qt.WindowModal)
Of course, if you can change the window/widget to a QDialog
, then none of the above is necessary, since the same functionality is provided by exec:
widget = QDialog()
widget.exec() # wait ...