1

I'm just experimenting with this. Whenever a user opens the program he should get 'online' and listen for connections.
Here the GUI gets loaded.

class AppUI(Frame):

    def __init__(self, parent):
        Frame.__init__(self, parent)
        self.parent = parent
        self.initUi()

    def initUi(self):
        self.parent.title("Redux")
        self.pack(fill=BOTH, expand=1)
        self.initMenu()
        self.initAudio()
        self.initMidi()
        self.initBroadcast()
        self.initFriendList()

But whenever I paste the code of my thread under initUi, it get's stuck on loading and my GUI doesn't show up. (keeps loading, because the thread is listening to connections)

thread2 = threading.Thread(target=Connection().getOnline("", 50007))
thread2.start()

Class Connection():
    def getOnline(self, host, port):
        self.s.bind((host, port))
        self.s.listen(2)
        print('Now online - listening to connections')
        conn, addr = self.s.accept()
        print("Connected to:", addr)

Why is my thread not working?

1 Answer 1

4

Your trouble is in this line:

thread2 = threading.Thread(target=Connection().getOnline("", 50007))

Here, you're actually calling Connection().getOnline("", 50007), which blocks. You haven't done this in the background, you've done it before your thread is started. You need to adjust your call to look like this:

thread2 = threading.Thread(target=Connection().getOnline, args = ("", 50007))
Sign up to request clarification or add additional context in comments.

1 Comment

bah too fast ... (+1 you beat me to the punch ...)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.