zoukankan      html  css  js  c++  java
  • python 多线程_thread

    import _thread
    import time
    
    def print_time(threadName, delay, iterations):
        start = int(time.time())
        for i in range(0,iterations):
            time.sleep(delay)
            seconds_elapsed = str(int(time.time()) - start)
            print (threadName if threadName else seconds_elapsed)
    
    try:
        _thread.start_new_thread(print_time, (None, 1, 10))
        _thread.start_new_thread(print_time, ("Fizz", 3, 3))
        _thread.start_new_thread(print_time, ("Buzz", 5, 3))
    except:
        print ("Error: unable to start thread")
    
    while 1:
        pass

    demo2

    import _thread
    import time
    
    def print_time(threadName, delay, iterations):
        start = int(time.time())
        for i in range(0,iterations):
            time.sleep(delay)
            seconds_elapsed = str(int(time.time()) - start)
            print (threadName if threadName else seconds_elapsed)
    
    try:
        _thread.start_new_thread(print_time, (None, 1, 10))
        _thread.start_new_thread(print_time, ("Fizz", 3, 3))
        _thread.start_new_thread(print_time, ("Buzz", 5, 3))
    except:
        print ("Error: unable to start thread")
    
    print("complete!")
  • 相关阅读:
    校验参考相关备份
    API接口设计
    redis 基础配置
    Apollo 统一配置中心
    http返回状态码记录
    ngnix实战
    OAuth2三方授权
    OAuth2授权协议记录
    KMP算法
    分治法
  • 原文地址:https://www.cnblogs.com/sea-stream/p/11062751.html
Copyright © 2011-2022 走看看