Queue를 사용할 때 Tk Python 앱이 계속 멈춤

CB

TK 앱을 실행할 때마다 멈춰서 Queue모듈 과 관련이 있다고 믿습니다 .

내 코드 :

 import socket, os, multiprocessing, queue
import tkinter as tk

#---global variables---#

setup = ''
cleintsocket = ''
port = 0
q = queue.Queue()

#---Defs---#

def setup():
    global host, port, user
    host = setup_host_box.get()
    port = setup_port_box.get()
    user = setup_user_box.get()
    if port == '':
        port = 8545
    create_sock(host, int(port))

def connect_buffer(self, hostname, connectingport):
    connect(self, hostname, connectingport)

def connect(self, hostname, connectingport):
    '''connects to a port'''
    if hostname == '':
        hostname = 'localhost'
    self.connect((hostname, connectingport))
    resvbackgroung = multiprocessing.Process(target = resv)
    resvbackgroung.start()
    chat()

def create_sock(nhost, nport):
    '''create the cleint's socket'''
    global cleintsocket
    cleintsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    connect(cleintsocket, nhost, nport)

def send(username, cleintsock):
    '''to send a message'''
    usrmsg = (username + ' - ' + chat_msg_box.get()).encode()
    cleintsock.send(usrmsg)

def resv():
    '''resive subscript, run through mutiprosses module'''
    while True:
        rmsg = cleintsocket.recv(1024).decode()
        q.put(rmsg)

def chat():
    '''loads chat page'''
    setup_host_text.pack_forget()
    setup_host_box.pack_forget()
    setup_port_text.pack_forget()
    setup_port_box.pack_forget()
    setup_user_text.pack_forget()
    setup_user_box.pack_forget()
    setup_confirm_button.pack_forget()
    chat_msg_display_text.pack()
    chat_msg_box.pack()
    chat_msg_send_button.pack()
    chat_disconnect_button.pack()
    while True:
        while not q.empty():
            msg = q.get()
            chat_msg_display_text.insert('END.END', msg)

def start():
    '''starts the setup page'''
    setup_host_text.pack()
    setup_host_box.pack()
    setup_port_text.pack()
    setup_port_box.pack()
    setup_user_text.pack()
    setup_user_box.pack()
    setup_confirm_button.pack()


def disconnect():
    '''safely closes the socket and sends a desconnect msg'''
    cleintsocket.send((user + 'has disconnected').encode())
    cleintsocket.close()
    quit()

def send_button_callback():
    '''add a buffer to allow time for 'cleintsocket' to be defined in 'create_sock()'''
    send(user, cleintsocket)

#---TK Setup---#

#--window setup--#

window = tk.Tk()
window.title('Chat')
window.geometry('600x600')
window.configure(background='#ffffff')

#--connection setup page--#

setup_host_text = tk.Label(window, text = 'Host')
setup_host_box = tk.Entry(window, bg = '#ffffff')
setup_port_text = tk.Label(window, text = 'Port')
setup_port_box = tk.Entry(window, bg = '#ffffff')
setup_user_text = tk.Label(window, text = 'Username')
setup_user_box = tk.Entry(window, bg = '#ffffff')
setup_confirm_button = tk.Button(window,text = 'Connect', command = setup)

#--chat page--#

chat_msg_box = tk.Entry(window, bg='#ffffff')
chat_msg_send_button = tk.Button(window, text = 'send', command = send_button_callback)
chat_msg_display_text = tk.Text(window, width=600, height=20, insertborderwidth = 3, wrap = 'word')
chat_disconnect_button = tk.Button(window, text = 'Disconnect', command = disconnect)

#--------------#

start()

감사합니다,

CB

Pythonista

문제는 귀하의 connect기능에 있습니다.

다중 resv처리를 설정하고 방금 생성 한이 프로세스의 대상으로 함수 넣습니다 .

그런 다음 프로세스를 시작하고 루프 chat가있는 바로 다음에 호출 while True합니다.

이것은 tkinter의 메인 이벤트 스레드를 차단합니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

dicomread를 사용할 때 Matlab이 특정 파일에서 멈춤

분류에서Dev

lldb에서 프로세스를 계속하려고 할 때 Python 스크립트가 멈춤

분류에서Dev

read ()를 사용할 때 BufferReader가 멈춤

분류에서Dev

토렌트를 NTFS 파티션으로 다운로드 할 때 계속 멈춤

분류에서Dev

토렌트를 NTFS 파티션으로 다운로드 할 때 계속 멈춤

분류에서Dev

Vim이 범위 밖으로 스크롤 할 때 계속 정지 / 멈춤

분류에서Dev

cef python-크기를 조정할 때 멈춤

분류에서Dev

iOS 8이 UserDefaults 개체를 업데이트 할 때 멈춤

분류에서Dev

iOS 8이 UserDefaults 개체를 업데이트 할 때 멈춤

분류에서Dev

프로세스를 시작할 때 Jframe이 멈춤

분류에서Dev

Ubuntu를 설치할 때 설치 프로그램이 멈춤

분류에서Dev

숫자를 생성 할 때 JavaScript 기능이 멈춤

분류에서Dev

Xcode 12.3이 계속 멈춤

분류에서Dev

새 장치를 사용할 때 genymotion 장치가 멈춤

분류에서Dev

QApplication에서 Windows :: SetParent를 사용할 때 GUI가 멈춤

분류에서Dev

PyQt4 스레드를 사용할 때 여전히 멈춤

분류에서Dev

wait_window ()를 사용할 때 Tkinter가 멈춤

분류에서Dev

스레드를 사용할 때 Gui가 멈춤

분류에서Dev

Android Studio에서 실행할 때 Flutter 앱이 멈춤

분류에서Dev

Yosemite 업데이트 후 앱을 실행할 때 Xcode가 멈춤

분류에서Dev

Julia를 실행할 때 Emacs가 멈춤

분류에서Dev

Mathematica를 호출 할 때 Sage가 멈춤

분류에서Dev

grub2를 설치할 때 멈춤

분류에서Dev

grub2를 설치할 때 멈춤

분류에서Dev

iOS에서 사진을 찍을 때 Titanium 앱이 멈춤

분류에서Dev

Angular에서 mat-form-field를 사용할 때 스플래시 화면이 멈춤

분류에서Dev

Cocos2d 응용 프로그램이 사운드를로드 할 때 멈춤

분류에서Dev

64 비트 또는 32 비트 버전의 Android Studio를 사용할 때 Gradle이 'build'또는 'assembleDebug'에서 멈춤

분류에서Dev

키보드 레이아웃 단축키를 사용할 때 Windows 10 Skype가 멈춤

Related 관련 기사

  1. 1

    dicomread를 사용할 때 Matlab이 특정 파일에서 멈춤

  2. 2

    lldb에서 프로세스를 계속하려고 할 때 Python 스크립트가 멈춤

  3. 3

    read ()를 사용할 때 BufferReader가 멈춤

  4. 4

    토렌트를 NTFS 파티션으로 다운로드 할 때 계속 멈춤

  5. 5

    토렌트를 NTFS 파티션으로 다운로드 할 때 계속 멈춤

  6. 6

    Vim이 범위 밖으로 스크롤 할 때 계속 정지 / 멈춤

  7. 7

    cef python-크기를 조정할 때 멈춤

  8. 8

    iOS 8이 UserDefaults 개체를 업데이트 할 때 멈춤

  9. 9

    iOS 8이 UserDefaults 개체를 업데이트 할 때 멈춤

  10. 10

    프로세스를 시작할 때 Jframe이 멈춤

  11. 11

    Ubuntu를 설치할 때 설치 프로그램이 멈춤

  12. 12

    숫자를 생성 할 때 JavaScript 기능이 멈춤

  13. 13

    Xcode 12.3이 계속 멈춤

  14. 14

    새 장치를 사용할 때 genymotion 장치가 멈춤

  15. 15

    QApplication에서 Windows :: SetParent를 사용할 때 GUI가 멈춤

  16. 16

    PyQt4 스레드를 사용할 때 여전히 멈춤

  17. 17

    wait_window ()를 사용할 때 Tkinter가 멈춤

  18. 18

    스레드를 사용할 때 Gui가 멈춤

  19. 19

    Android Studio에서 실행할 때 Flutter 앱이 멈춤

  20. 20

    Yosemite 업데이트 후 앱을 실행할 때 Xcode가 멈춤

  21. 21

    Julia를 실행할 때 Emacs가 멈춤

  22. 22

    Mathematica를 호출 할 때 Sage가 멈춤

  23. 23

    grub2를 설치할 때 멈춤

  24. 24

    grub2를 설치할 때 멈춤

  25. 25

    iOS에서 사진을 찍을 때 Titanium 앱이 멈춤

  26. 26

    Angular에서 mat-form-field를 사용할 때 스플래시 화면이 멈춤

  27. 27

    Cocos2d 응용 프로그램이 사운드를로드 할 때 멈춤

  28. 28

    64 비트 또는 32 비트 버전의 Android Studio를 사용할 때 Gradle이 'build'또는 'assembleDebug'에서 멈춤

  29. 29

    키보드 레이아웃 단축키를 사용할 때 Windows 10 Skype가 멈춤

뜨겁다태그

보관