python - PyQT Segmentation fault (sometimes) -


I am creating an interface to manage some servers, restart basic tasks and think in this way I have created the interface, programming in QTCreator and PyQT5 , it's working properly (sometimes).

Sometimes it works just fine, for the second time, the arguments of the segmentation fault or QObject :: connect: type 'QTextCursor' can not be queued (Make sure 'QTextCursor' is registered using qRegisterMetaType ().)

This is when I restart_nginx in main window hit, maybe there is some problem with thread management, this is the first project with which i PyQT / QT

thanks.

  #! / Usr / bin / env python # - * - coding: utf-8 - * - the import __future__ import Unikod_laitrs PyQt5.QtCore import Prmico import * from PyQt5.QtGui import * Rt of PyQt5.QtWidgets impo * ui_mainwindow imports Ui_MainWindow Server = {"Mars": "198.58.112. ***", "Saturn": "198.58.116. ***"} green = "RGB (83, 236, 17)" default = "RGB (154) , "Color +"; Border: 1 px solid black; "Class worker (QObject)," black "=" yellow "red =" red "pw = 'pass' df format_stats (color): return" background color: ): Def __init __ (auto, ui, server, command = Oi not pseudo = false, * Arges, ** kwargs): QObject .__ init __ (self, * args, ** kwargs) self.ssh = paramiko.SSHClient () self.ssh.set_missing_host_key_policy (paramiko.AutoAddPolicy () ) Self.ui = ui self.command = command self.sudo = sudo self.server = server terminated = pyqtSignal () @pyqtSlot (except as paramiko.SSHException excluding self.ssh.connect (self.server, user name = 'Hercules', password = pw) :) try to execute def (self): self.ui.status_restart_nginx.setStyleSheet (format_status (color = yellow)): Self.ui.log.append ( "ERRO: to connect Impossible:% s ", e) try self.ui.status_restart_nginx.setStyleSheet (format_status (color = red)): session = self.ssh.get_transport ()Open_session () Session.get_pty () f = session.makefile () session.exe C_command ("ls -lh") #if self.sudo: # session.send (pw + '\ n') f.readlines in row For: (): self.ui.log.append (line) f.close () self.ssh.close () self.ui.status_restart_nginx.setStyleSheet (format_status (color = green)) Except as an exception: self .ui.status_restart_nginx.setStyleSheet (format_status (color = red)) print 'errinho:', e self .finished.emit () class MainWindow (QMainWindow, Ui_MainWindow): def __init __ (self, parent = none, ** kwargs): Super (MainWindow, self) .__ init __ (parent) self.setupUi (self) self.btn_restart_nginx.clicked .connect (self.restart_nginx) self.thread_worker = no self.obj_worker = none def create_worker (Swi Yum, server, command = none, sudo = false): self.thread_worker = qthread (original = self) self.obj_worker = worker (ui = self, server = server, command = command, pseudo = pseudo) self.obj_worker. moveToThread (self.thread_worker) self.obj_worker.finished.connect (self.thread_worker.quit) self.thread_worker.started.connect (self.obj_worker.execute) self.thread_worker.start () def restart_nginx (self): Self.status_restart_nginx .setStyleSheet (format_status (color = yellow) self.log.append ("(Mars) Nginx: Trying to restart front-end ...") self.create_worker (server ["Mars"], command = "Sudo service nginx restart", sudo = true) if __name __ == "__ main__": from sys import argv, exit app = QApplication m = Sh Exec_ ())  

Enter image details here

Never attempting to change the GUI inside the worker thread, only the GUI inside the main GUI thread Update from, and do not give context to GUI elements to worker threads.

The GUI is the simplest and safest way to communicate between thread and worker threads. When the signs are in this way, they are queued, and the slot is used in the receiver's thread when it controls the return on the event-loop.

In PyQt,

for all the sources underlined for these reasons

Comments