【Python】动态获取python类名、函数名&多线程
import time
import random
import threading
import inspect def get_current_function_name():
return inspect.stack()[1][3] class Inclass:
def __init__(self):
print 'Inclass 初始化'
def execIn(self,i):
rand = int(random.random() * 10)
print i,'【%s.%s】---%s--开始执行,暂停%d秒' % (self.__class__.__name__, get_current_function_name(),time.ctime(),rand)
time.sleep(rand)
return i class MyThread(threading.Thread):
def __init__(self,func,args,name = ''):
threading.Thread.__init__(self)
self.name = name
self.func = func
self.args = args
def getResult(self):
return self.res
def run(self):
self.res = self.func(*self.args) class Outclass:
def __init__(self):
print 'OutClass初始化'
def execOut(self):
InC = Inclass()
length = 1000
threadlen = 10
k = 0
i = 0
while i < length:
nloops = range(threadlen)
threads = []
for j in range(threadlen):
t = MyThread( InC.execIn, (i,))
i += 1
threads.append(t)
for i in nloops:
threads[i].start()
for i in nloops:
threads[i].join() for i in nloops:
print '-----result:',threads[i].getResult() print k,'【%s.%s】--%s--开始执行多线程第%d个小循环' % (self.__class__.__name__, get_current_function_name(),time.ctime(),k)
k += 1 OC = Outclass()
OC.execOut()
【Python】动态获取python类名、函数名&多线程的更多相关文章
- [Python] 动态函数调用(通过函数名)
2018-04-09 update 利用python中的内置函数 eval() ,函数说明: def eval(*args, **kwargs): # real signature unknown & ...
- python 动态生成变量名以及动态获取变量的变量名
前言需求: 必须现在需要动态创建16个list,每个list的名字不一样,但是是有规律可循,比如第一个list的名字叫: arriage_list_0=[],第二个叫arriage_list_1=[] ...
- 类名+函数名(参数1,参数2.....){.......return this;}
下述的函数是这样定义的: 类名+函数名(参数1,参数2.....){.......return this;} int +函数名(参数1,参数2.....){.......return int;} sh ...
- python 动态获取当前运行的类名和函数名的方法
一.使用内置方法和修饰器方法获取类名.函数名 python中获取函数名的情况分为内部.外部,从外部的情况好获取,使用指向函数的对象,然后用__name__属性 复制代码代码如下: def a():pa ...
- python 获取当前运行的类名函数名
import inspect def get_current_function_name(): return inspect.stack()[1][3] class MyClass: def func ...
- python 获取当前调用函数名等log信息
import sys funcName = sys._getframe().f_back.f_code.co_name #获取调用函数名 lineNumber = sys._getframe().f_ ...
- python动态获取对象的属性和方法 (转载)
首先通过一个例子来看一下本文中可能用到的对象和相关概念. #coding:utf-8 import sys def foo():pass class Cat(object): def __init__ ...
- python动态获取对象的属性和方法 (转)
转自未知,纯个人笔记使用 首先通过一个例子来看一下本文中可能用到的对象和相关概念. #coding:utf-8 import sys def foo():pass class Cat(object): ...
- python动态获取对象的属性和方法
http://blog.csdn.net/kenkywu/article/details/6822220首先通过一个例子来看一下本文中可能用到的对象和相关概念.01 #coding: UTF- ...
- 【Python】—— 获取当前运行函数名称和类方法名称
原文出处: python笔记19-获取当前运行函数名称和类方法名称 获取函数名称 1.在函数外部获取函数名称,用.__name__获取 2.函数内部获取当前函数名称,用sys._getframe(). ...
随机推荐
- VS中批量删除注释
批量删除: 按ctrl+H 选上正则表达式 Find what: //.* Replace with: (空) 点replace all就行了
- 五个你必须知道的javascript和web debug技术
转:http://js8.in/2013/11/20/%E4%BA%94%E4%B8%AA%E4%BD%A0%E5%BF%85%E9%A1%BB%E7%9F%A5%E9%81%93%E7%9A%84j ...
- hdu 1532 最大流
#include <cstdio> #include <iostream> #include <algorithm> #include <queue> ...
- Linux debugger lldb
https://lldb.llvm.org/ https://lldb.llvm.org/lldb-gdb.html https://lldb.llvm.org/tutorial.html
- C++内联函数详解
1.函数调用原理 "编译过程的最终产品是可执行程序--由一组机器语言指令组成.运行程序时,操作系统将这些指令载入计算机内存中,因此每条指令都有特定的内存地址.计算机随后将逐步执行这些指令.有 ...
- Oracle PLSQL Demo - 16.弱类型REF游标[没有指定查询类型,已指定返回类型]
declare Type ref_cur_variable IS REF cursor; cur_variable ref_cur_variable; rec_emp scott.emp%RowTyp ...
- org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xm
org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xm 检查jar包是否正确以及配置的xm ...
- grails3.1.5 com.mysql.jdbc.Driver
[报错] Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver at java.net.URLClassLoader$1 ...
- 多行文字在一个div中上下左右居中
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- 基于jquery带时间轴的图片轮播切换代码
基于jquery图片标题随小圆点放大切换.这是是一款带时间轴的图片轮播切换代码.效果图如下: 在线预览 源码下载 实现的代码. html代码: <div id="decoroll2 ...