Hello!
I'm writing a Python Panel for Houdini.
I need to execute Python code asynchronously not blocking the main Qt or Python code, simple multithreading doesn't work (most likely because of the global python interpreter lock).
But when I use python multiprocessing, this works as stand alone widget, but within Houdini, even when using multiprocessing.get_context('spawn'), python will fork and not spawn a new process, yielding a new Houdini copy.
Is it possible to make python multiprocessing work within Houdini (python panel)?
I'm currently running on windows, but in the long run, the panel should work on any plaform.
Thank you in advance for your help.
multiprocessing in Houdini Python panel
1650 3 5- _Markus_
- Member
- 1 posts
- Joined: Feb. 2023
- Offline
- Jonathan de Blok
- Member
- 274 posts
- Joined: July 2013
- Offline
Have you tried using Qt threads? https://realpython.com/python-pyqt-qthread/ [realpython.com]
More code, less clicks.
- ivan
- Member
- 83 posts
- Joined: July 2005
- Offline
- ivan
- Member
- 83 posts
- Joined: July 2005
- Offline
ok, well, if anyone else comes across this thread, here is 1 working bit of code. Thank you for holding the duck.
from PySide2 import QtWidgets from PySide2 import QtGui from PySide2 import QtCore import time class VideoThread(QtCore.QThread): def setStuff(self, vidscr, butt): self.vidscr = vidscr self.butt = butt def run(self): loop = True while loop: # blink blink pm = QtGui.QPixmap(320, 240) pm.fill(QtGui.QColor('darkGray')) self.vidscr.setPixmap(pm) time.sleep(1) pm.fill(QtGui.QColor('cyan')) self.vidscr.setPixmap(pm) time.sleep(1) if not self.butt.isChecked(): loop = False class vidWidg(QtWidgets.QWidget): def buildUI(self): self.videoScreen = QtWidgets.QLabel(self) self.startButton = QtWidgets.QPushButton("run blinky", self) self.startButton.setCheckable(True) self.startButton.toggled.connect(self.togg) layout = QtWidgets.QVBoxLayout() layout.addWidget(self.videoScreen) layout.addWidget(self.startButton) self.setLayout(layout) def togg(self, val): if val: self.thread = VideoThread() self.thread.setStuff(self.videoScreen, self.startButton) self.thread.start() else: self.thread.wait() self.thread.quit() def createInterface(): root_widget = vidWidg() root_widget.buildUI() return root_widget
Edited by ivan - Sept. 1, 2023 21:06:46
-
- Quick Links