python 对类的成员函数开启线程的方法

yipeiwu_com6年前Python基础

如下所示:

# -*- coding: utf-8 -*-
import threading
import thread
import time


class Test(object):
  def __init__(self):
    # threading.Thread.__init__(self)
    self._sName = "machao"

  def process(self):
    #args是关键字参数,需要加上名字,写成args=(self,)
    th1 = threading.Thread(target=Test.buildList, args=(self,))
    th1.start()
    th1.join()

  def buildList(self):
    while True:
      print "start"
      time.sleep(3)


test = Test()
test.process()

以上这篇python 对类的成员函数开启线程的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

详解DeBug Python神级工具PySnooper

PySnooper 在 GitHub 上自嘲是一个“乞丐版”调试工具(poor man's debugger)。 一般情况下,在编写 Python 代码时,如果想弄清楚为什么 Pytho...

python3.7环境下安装Anaconda的教程图解

python3.7环境下安装Anaconda的教程图解

下载Anaconda安装包 官网下载或是在清华大学镜像站下载,我安装的是下面这个版本:   安装过程 配置环境 将anaconda的scripts文件夹路径添...

python 类之间的参数传递方式

练手记录以及调试步骤. class A(object): def __init__(self,a="A"): print("enter",a) print("le...

json跨域调用python的方法详解

本文实例讲述了json跨域调用python的方法。分享给大家供大家参考,具体如下: 客户端: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML...

Python实现的远程登录windows系统功能示例

本文实例讲述了Python实现的远程登录windows系统功能。分享给大家供大家参考,具体如下: 首先安装wmi 命令: pip install wmi 然后会报错缺少pyw...