Skip to main content

Classic Signals

Библиотека предоставляет просую реализацию паттерна Observer для инверсии контроля через сигналы и реакции.

Потокобезопасно.

В одном месте программы мы объявляем сигналы, пользуясь декоратором signal, в других местах приложения пишем реакции на этих сигналов. Реакции - это любой вызываемый объект, принимающий один аргумент - инстанс сигнала. Это может быть и просто функция или метод. Последнее, что нужно, это инстанс класса Hub. В Hub перед началом работы можно зарегистрировать реакции, потом можно вызвать у него метод notify, передав в него инстанс сигнала, и Hub вызовет все реакции, относящиеся к сигналу.

Реакции исполняются последовательно в единственном текущем потоке. Не рекомендуется создавать новые потоки из сигналов. Этот механизм предназначается для связки разных частей кода с инверсией зависимости, не для распараллеливания задач.

Пример:

from dataclasses import dataclass

from classic.signals import Hub


@dataclass
class SomethingHappened:
    some_field: int


@dataclass
class SomethingAnotherHappened:
    some_field: int


@dataclass
class SomeHandlers:
    hub: Hub
    
    def __post_init__(self):
        self.hub.add_reaction(
            SomethingHappened,
            self.on_something_happened,
        )
        self.hub.add_reaction(
            SomethingAnotherHappened,
            self.on_something_another_happened,
        )
    
    def on_something_happened(self, signal: SomethingHappened):
        print(f'Что-то произошло: {signal}')
    
    def on_something_another_happened(self, signal: SomethingAnotherHappened):
        print(f'Что-то еще произошло: {signal}')


hub = Hub()
SomeHandlers(hub=hub)

signal_1 = SomethingHappened(some_field=0)
signal_2 = SomethingAnotherHappened(some_field=0)

hub.notify(signal_1, signal_2)

Metadata

Release files for classic-signals 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for classic-signals 1.0.0
File Size Uploaded Provenance
classic_signals-1.0.0.tar.gz 4.2 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for classic-signals 1.0.0
File Interpreter ABI Platform
classic_signals-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.8 kB

Release files / classic_signals-1.0.0.tar.gz

Download URL classic_signals-1.0.0.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
dbec4524462bfde2c823327cc248823b6249c11df811a62a2dfaab6d86177bde
BLAKE2b-256 checksum
How to use checksums
b9e55566e51f7e1a165dd631736e81ee354146a65ecfc5e5dbc754761a777eed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.

Transparency log

Release files / classic_signals-1.0.0-py3-none-any.whl

Download URL classic_signals-1.0.0-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c90fa757b301ef60375ac20c68a736e6cf02f6aa62e7080fa048c3bb85bb7c80
BLAKE2b-256 checksum
How to use checksums
e8184393af3b0fb505d86382633314a0beab2106554a61df507c2df3506f3c9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.

Transparency log

Security for classic-signals 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for classic_signals-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page