Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Extended semaphores of flask

Shulou Source: shulou.com Published: 2022-06-03 06:01:28 11月24日 Update

# pip install blinkerfrom blinker import signals = signal ('semaphores ')def each(num): print("each {}".format(num))def full_singal(num): print("full_time {}".format(num))s.connect(each)s.connect(full_singal, sender = 2)for num in range(1, 4): s.send(num) The result is as follows: each 1each 2round 2each 3#or abbreviated:from blinker import signals = signal("test start")@s.connectdef each(round) print("each {}".format(round))Flask built-in signal: flask.template_rendered: sent when template rendering is successful, this signal is called together with the dictionary of template instance template context. Flask.request_started: After the request context is established, sent before request processing begins, subscribers can access the request using standard proxies such as request. flask.request_finished: Sent before the response is sent to the client, may pass a response. flask.got_request_exception: Sent when an exception is thrown in request processing, the exception itself is passed to the subscription function via execution. Flask.request_tearing_down: Sent when destruction is requested, it is always called, even if an exception occurs. Flask.appcontext_tearing_down: Sent when application context is destroyed, it is always called, even if an exception occurs.

Tags: Signal up and down context template processing subscription semaphore success function dictionary instance client client time standard result subscriber should be sent agent application Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Xiaomi Huawei Redmi MariaDB