'Hanging program after clicking on start button
in this code i create two clases one is for my gui (class me) and soc is for when the button start clicked the socket then should listen to local host in port 8080.When i run the progarm and clicked the start button it worked and idle showed me the listening message but then the program hanged.

what problem is in this code that cause this hanging?
import kivy
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
import socket
class soc():
def __init__(self,s,conn, addr):
self.s=s
self.conn=conn
self. addr= addr
self.s=socket.socket()
self.s.bind(('localhost',8080))
def listen(self,click):
self.s.listen()
print ('listening...')
self.conn,self. addr=self.s.accept()
soc=soc('s','conn','addr')
class me(App):
def __init__(self,b,g,l,t):
super(me, self).__init__()
self.b=Button(text='start',on_press =soc.listen)
self.g=GridLayout(cols=4)
self.l=Label(text='label')
self.t=TextInput()
def build(self):
self.g.add_widget(self.b)
self.g.add_widget(self.t)
self.g.add_widget(self.l)
return self.g
m=me('b','g','l','t')
m.run()
Solution 1:[1]
You need to run your listen() method in a different thread. Use something like:
Thread(target=self.listen).start()
See the documentation. Running listen() on the main thread holds that thread and prevents the GUI from updating.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | John Anderson |
