Flashing console when running exe packaged by pyinstaller #8420
-
I use Below is the pseudocode of my program: import multiprocessing
def GetPredict(screenshot):
results = model(screenshot)
for i, r in enumerate(results):
# Plot results image
im_bgr = r.plot() # BGR-order numpy array
im_rgb = Image.fromarray(im_bgr[..., ::-1]) # RGB-order PIL image
return xxx
class Window(QMainWindow):
def __init__(self):
super().__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.setWindowFlags(Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground)
self.timer = QTimer()
self.timer.timeout.connect(self.LoopFunction)
self.ui.Start_Button.clicked.connect(self.start_loop)
self.ui.Stop_Button.clicked.connect(self.stop_loop)
def LoopFunction(self):
screnshot = xxx
result = GetPredict(screenshot)
def start_loop(self):
self.timer.start(1000) # tick
def stop_loop(self):
self.timer.stop()
if __name__ == '__main__':
# added
multiprocessing.freeze_support()
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_()) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Sounds like your code (or the 3rd party code you are using) is spawning subprocesses with programs/command that require console. And since the parent application does not have a console, each such subprocesses opens their own console. If you are using https://github.com/ultralytics/ultralytics/blob/911a0edd2d1b47c28e1eef657859dbb9bcffb13f/ultralytics/utils/torch_utils.py#L164 It ends up using Nothing we can do about that; maybe explicitly specifying the device to suppress the auto-selection will help. Note that if you call See ##8211 and https://pyinstaller.org/en/stable/common-issues-and-pitfalls.html#when-to-call-multiprocessing-freeze-support |
Beta Was this translation helpful? Give feedback.
Sounds like your code (or the 3rd party code you are using) is spawning subprocesses with programs/command that require console. And since the parent application does not have a console, each such subprocesses opens their own console. If you are using
ultralytics
yolov8 on CPU, then this device auto-selection codepath might be the culprit:https://github.com/ultralytics/ultralytics/blob/911a0edd2d1b47c28e1eef657859dbb9bcffb13f/ultralytics/utils/torch_utils.py#L164
https://github.com/ultralytics/ultralytics/blob/911a0edd2d1b47c28e1eef657859dbb9bcffb13f/ultralytics/utils/torch_utils.py#L73
It ends up using
cpuinfo.get_cpu_info
, which seems to do several subprocess calls, e.g. towmi
on Wind…