0

Hey, this time I'm back with a threading error!

I need to write code that gets the address of a message sender while at the same time letting the user know that the pygame didn't freeze, so I started a thread to keep control of the screen while searching for a connection.

Anyway, while testing my threads in a test file, I kept getting this C++ Runtime or a "This Program encountered an error and needed to close." error whenever I called Thread.start().

I'm not sure why I'm getting this error, and would appreciate some help figuring this out!

Here's the code in case it's needed

from threading import Thread

Var = 1

class T(Thread):

    def run(self):
        global Var
        print "This is thread " + str(Var) + "speaking."
        print "Hello and Goodbye!"
        Var += 1

for x in range(20):
    T().start()
3
Contributors
5
Replies
7
Views
8 Years
Discussion Span
Last Post by Azurea
0

Your T object doesn't live long enough to allow the thread to run safely.
Create your T objects, then start them, then let the instance die.

0

Oddly enough that didn't work O_O. One of the times I did that and IDLE just closed without even giving off an error!

0

You also need to have your main program stay alive long enough for the threads to do their work.
Take a canonical example and work from there. I could look one up for you but we both have the internet.

0

Hmm.. Well strangely enough it works on my machine (XP)
From idle and from cmd.

Not sure what the problem is, but if you need to get the address of a messege sender then just do that in the thread (if it's sockets it will be safe)

0

I tried using a thread, but the game crashed once I used the thread.start() again. I'll try re-installing IDLE after school and see what happens...

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.