<reponame>garyhu1/first-python<filename>thread/python_thread.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

'线程'

__author__ = 'garyhu'

import time,threading;

def loop():
    print("thread %s is running ..." % threading.current_thread().name);
    
    n = 0;
    while n < 5:
        n = n + 1;
        print('thread %s is looping >>> %d' % (threading.current_thread().name,n));
        time.sleep(1)
    print("thread %s ended." % threading.current_thread().name);    
    
    
if __name__ == '__main__':
    print("thread %s is running..." % threading.current_thread().name);
    thread = threading.Thread(target=loop,name='SubLoopThread');
    thread.start();
    thread.join();
    print("thread %s ended." % threading.current_thread().name);    
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

'线程'

__author__ = 'garyhu'

import time,threading;

def loop():
    print("thread %s is running ..." % threading.current_thread().name);
    
    n = 0;
    while n < 5:
        n = n + 1;
        print('thread %s is looping >>> %d' % (threading.current_thread().name,n));
        time.sleep(1)
    print("thread %s ended." % threading.current_thread().name);    
    
    
if __name__ == '__main__':
    print("thread %s is running..." % threading.current_thread().name);
    thread = threading.Thread(target=loop,name='SubLoopThread');
    thread.start();
    thread.join();
    print("thread %s ended." % threading.current_thread().name);
#!/usr/bin/env python3 # -*- coding: utf-8 -*-