zoukankan      html  css  js  c++  java
  • threading 多线程

    # coding:utf-8
    import time
    
    from threading import Thread
    
    
    def foo(x):#这里可以带参数def foo(x)
        print "foo start 启动耗时".decode('utf-8'), time.ctime()
        time.sleep(x)
        print "foo start 运行结束:".decode('utf-8'), time.ctime()
        return "aaa"
    def soo(x):
        print "soo start 启动耗时".decode('utf-8'), time.ctime()
        time.sleep(x)
        print "soo start 运行结束".decode('utf-8'), time.ctime()
        return "bbb"
    
    
    class MyThread1(Thread):
        def __init__(self, number):
            Thread.__init__(self)
            self.num=number
    
        def run(self):
            print "run() start foo", time.ctime()
            self.result = foo(self.num)#模拟耗时
    
        def get_result(self):
            return self.result#获取返回值
    
    class MyThread2(Thread):
        def __init__(self, number):
            Thread.__init__(self)
            self.num = number
    
        def run(self):
            print "run() start soo", time.ctime()
            self.result = soo(self.num)
    
        def get_result(self):
            return self.result
    
    thd1 = MyThread1(3)
    thd2 = MyThread2(5)
    print "pre start
    	"
    thd1.start()
    print "thd1 started
    	"
    thd2.start()
    print "
    	"
    print "thd2 started
    	"
    thd1.join()
    thd2.join()
    print " 
    	"
    print "all done"
    print thd1.get_result(), time.ctime()
    print thd2.get_result(), time.ctime()
  • 相关阅读:
    Hdu 1257最少拦截系统
    删除mysql__转
    sql 入门的小例子熟悉一下_这可是一个转转转贴 :)
    header 用法_转
    java_json 转换 文件在file中
    javascript_php 正则匹配 转
    mysql 忘记密码转_kinghu
    php 通用下载
    明天就是新年开始
    翻译 有助于程序命名
  • 原文地址:https://www.cnblogs.com/hanxing/p/8921620.html
Copyright © 2011-2022 走看看