
Security News
Researcher Exposes Zero-Day Clickjacking Vulnerabilities in Major Password Managers
Hacker Demonstrates How Easy It Is To Steal Data From Popular Password Managers
aio_pubsub ########
.. code-block:: shell
pip install aiopubsub-py3 pip install aiopubsub-py3[redis]
.. code-block:: python
from aiopubsub import Pubsub
async def main():
async with Pubsub(Pubsub.REDIS, port=16379, namespace="cs", role=PubsubRole.PUB) as pub:
count = await pub.publish("foo", {"test": 1})
print(count)
count = await pub.publish("foo", {"test": 2})
print(count)
count = await pub.publish("foo", {"test": 3})
print(count)
.. code-block:: python
from aiopubsub import Pubsub, PubsubRole
async def print_msg(channel, msg):
print(f"sub msg: {channel} -- {msg}")
async def main():
channels = ["foo"]
async with Pubsub(Pubsub.REDIS, port=16379, namespace="cs", role=PubsubRole.SUB) as sub:
await sub.subscribe(*channels)
async for k in sub.listen(handler=print_msg):
print(k)
await sub.unsubscribe(*channels)
.. code-block:: python
from aiopubsub import Pubsub
async def print_msg(channel, msg):
print(f"psub msg: {channel} -- {msg}")
async def main():
channels = ["foo*"]
async with Pubsub(Pubsub.REDIS, port=16379, namespace="cs", role=PubsubRole.SUB) as psub:
await psub.psubscribe(*channels)
async for k in psub.listen(handler=print_msg):
print(k)
await psub.unsubscribe(*channels)
.. code-block:: python
from aiopubsub import Pubsub
async def print_msg(channel, msg):
print(f"psub msg: {channel} -- {msg}")
async def main():
channels = ["foo*"]
pubsub = Pubsub(Pubsub.REDIS, port=16379, namespace="cs")
await pubsub.publish("foo", {"test": 1}) # 角色设置为PUB,执行成功
await pubsub.subscribe(*channels) # 角色为PUB,无法订阅抛出异常
await pubsub.close() # 角色释放
await pubsub.subscribe(*channels) # 角色设置为SUB,执行成功
print(pubsub.backend.role)
await pubsub.publish("foo", {"test": 1}) # 角色为SUB,无法发布抛出异常
async with pubsub:
await pubsub.unsubscribe(*channels) # 角色为SUB,执行成功
# async with 退出作用域,角色释放
await pubsub.publish("foo", {"test": 1}) # 角色设置为PUB,执行成功
FAQs
aio pubsub
We found that aiopubsub-py3 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Hacker Demonstrates How Easy It Is To Steal Data From Popular Password Managers
Security News
Oxlint’s new preview brings type-aware linting powered by typescript-go, combining advanced TypeScript rules with native-speed performance.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.