So I found an example that shows
import threading
from threading import Thread
def func1():
print 'Working'
def func2():
print 'Working'
if __name__ == '__main__':
Thread(target = func1).start()
Thread(target = func2).start()
and this works.
But how does it work when I usually have an object with the function. Here are 2 functions I normally use.
statusbar()
copyfrom(servername.strip())
How do I add servername.strip() to the below?
Thread(target = statusbar).start()
Thread(target = copyfrom).start()
The target
should be a function, so define your own function that does what you want:
def doSomething():
copyfrom(servername.strip())
and hand it to your Thread
.
Thread(target=doSomething).start()
If you want to do it in a single line, you could use an anonymous function:
Thread(target=lambda: copyfrom(servername.strip())).start()
As cᴏʟᴅsᴘᴇᴇᴅ mentions in his answer, you can also specify arguments for the callback as a tuple:
Thread(target=copyfrom, args=(servername.strip(), )).start()
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments