忍无可忍,今天把python3.1换到了2.7,不然每次发现写个代码编译不过我就得去查这是不是又是3.0的改变之处!我还是个初学者,没那么多时间在那上纠结!
Why multi-thread?
-
Multiple threads within a process share the same data space with the main thread and can therefore share information or communicate with each other more easily than if they were separate processes.
-
Threads sometimes called light-weight processes and they do not require much memory overhead; theycare cheaper than processes.
启动一个线程:
thread.start_new_thread ( function, args[, kwargs] )
#!/usr/bin/python
import thread
import time
# Define a function for the thread
def print_time( threadName, delay):
count = 0
while count < 5:
time.sleep(delay)
count += 1
print "%s: %s" % ( threadName, time.ctime(time.time()) )
# Create two threads as follows
try:
thread.start_new_thread( print_time, ("Thread-1", 2, ) )
thread.start_new_thread( print_time, ("Thread-2", 4, ) )
except:
print "Error: unable to start thread"
while 1:
pass
-
run(): The run() method is the entry point for a thread.
-
start(): The start() method starts a thread by calling the run method.
-
join([time]): The join() waits for threads to terminate.
-
isAlive(): The isAlive() method checks whether a thread is still executing.
-
getName(): The getName() method returns the name of a thread.
-
setName(): The setName() method sets the name of a thread.
未完待续。。。。。。。。。。。。。。。。。。。