python信号系统signal

Posted zhangphil

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python信号系统signal相关的知识,希望对你有一定的参考价值。

python信号系统signal

 

myapp.py:

import sys
import time
from blinker import signal as b_sig

format_num = 1000000000

appsig = b_sig('app_start')


@appsig.connect
def demo(msg, **kw):
    print(msg, kw, sys._getframe().f_code.co_name, sys._getframe().f_lineno, time.time_ns() / format_num)
    time.sleep(1)
    print(msg, kw, sys._getframe().f_code.co_name, sys._getframe().f_lineno, time.time_ns() / format_num)
    return msg

 

main.py

from myapp import appsig

if __name__ == '__main__':
    r=appsig.send('OK',code=1)
    print(r)

 

输出:

OK 'code': 1 demo 12 1662700459.4300745
OK 'code': 1 demo 14 1662700460.430196
[(<function demo at 0x0000020A43E9E040>, 'OK')]

 

GitHub - pallets-eco/blinker: A fast Python in-process signal/event dispatching system.A fast Python in-process signal/event dispatching system. - GitHub - pallets-eco/blinker: A fast Python in-process signal/event dispatching system.https://github.com/pallets-eco/blinker

 

以上是关于python信号系统signal的主要内容,如果未能解决你的问题,请参考以下文章

Python信号处理模块signal

Python和Signal

python学习笔记——信号模块signal

python 之信号Signal

Python模块之信号学习(signal)

转:python signal信号