Код: Выделить всё
import os
import multiprocessing
shared_queue = multiprocessing.Queue()
class MyProcess:
def foo(self, nb):
pid = os.getpid()
output = f"Process id = {pid}\nReceived nb = {nb}"
shared_queue.put(output)
print(output)
def do_stuff(self):
pool_size = 8
p = multiprocessing.Pool(pool_size)
p.map(self.foo, range(pool_size))
< /code>
Я заменил функцию загрузки FTP на меньшую печать, но я получаю одинаковую проблему с обоими.import sys
from PySide6.QtWidgets import QApplication, QWidget, QLabel, QPushButton, QVBoxLayout
from PySide6.QtCore import QThread, Signal
from other_module import MyProcess, shared_queue
class MyThread(QThread):
my_sig = Signal(str)
def run(self):
while True:
text = shared_queue.get(block=True)
self.my_sig.emit(text)
class Window(QWidget):
def __init__(self):
super().__init__()
self.label = QLabel("label to update")
self.button = QPushButton("Do Stuff")
self.layout = QVBoxLayout()
self.layout.addWidget(self.label)
self.layout.addWidget(self.button)
self.setLayout(self.layout)
self.thread = MyThread()
self.thread.my_sig.connect(self.update_label)
self.thread.start()
self.button.clicked.connect(self.button_handler)
def update_label(self, text):
self.label.setText(text)
print(text)
self.label.update()
QApplication.processEvents()
def button_handler(self):
bar = MyProcess()
bar.do_stuff()
if __name__ == "__main__":
app = QApplication([])
window = Window()
window.show()
sys.exit(app.exec())
Подробнее здесь: https://stackoverflow.com/questions/796 ... ol-pyside6