Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Is a function defined in the main thread and called from another run from the main thread or calling thread

Let's say I have a program as such:

import threading

def dosomething():
    print "Something"

class thread2(threading.Thread):
    def run():
        dosomething()

thread2().start()

would dosomething() run from the main thread, where it was defined, or thread2, where it was called?

I'm using this for a pygame program, since you can't call pygame's methods from multiple classes.

like image 916
ethguo Avatar asked Sep 11 '26 05:09

ethguo


1 Answers

It doesn't matter where you declared the function. The function is going to be executed by the thread that calls it.

like image 134
JoseP Avatar answered Sep 13 '26 18:09

JoseP