Python 实现异步调用函数的示例讲解

yipeiwu_com6年前Python基础

async_call.py

#coding:utf-8
from threading import Thread

def async_call(fn):
  def wrapper(*args, **kwargs):
    Thread(target=fn, args=args, kwargs=kwargs).start()

  return wrapper

test.py

from time import sleep
from async_call import async_call

class AA:
  @async_call
  def hello( self ):
    self.__count += 1
    print(int(time.()))
    sleep(2)
    print(int(time.()))
    return

if __name__ == "__main__":

  AA().hello()

以上这篇Python 实现异步调用函数的示例讲解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python 函数list&read&seek详解

Python 函数list&read&seek详解

一、函数list (1)定义:用打开的文件作为参数,把文件内的每一行内容作为一个元素 (2)格式:list(文件) (3)例子: with open(r"test01.txt",'r...

python获取一组汉字拼音首字母的方法

本文实例讲述了python获取一组汉字拼音首字母的方法。分享给大家供大家参考。具体实现方法如下: #!/usr/bin/env python # -*- coding: utf-8...

Python使用lambda表达式对字典排序操作示例

本文实例讲述了Python使用lambda表达式对字典排序操作。分享给大家供大家参考,具体如下: lambda表达式也常用于字典排序,既然写到字典排序,那就把按键排序和按值排序都写写好了...

PyQt5每天必学之工具提示功能

PyQt5每天必学之工具提示功能

本文将教会我们如何使用PyQt5控件的工具提示功能。 #!/usr/bin/python3 # -*- coding: utf-8 -*- """ PyQt5 教程 这个例子显示...

python邮件发送smtplib使用详解

本文实例为大家分享了python邮件发送smtplib使用具体代码,供大家参考,具体内容如下 文件形式的邮件 #!/usr/bin/env python3 #coding: utf...