Commit 7c8e795d by 王维

master

parents
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
*.log
*.rar
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
vendor/
.idea
.DS_Store
config.json
build
xxd
obs
dat
station
tle
sql
log
.idea
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
# Readme
main.py是项目主入口,加载MainWindow,个人测试代码直接存放到test目录中,先在test中进行充分测试,再考虑移动到其他目录
pycharm设置当前工程为`Sources root`目录很重要,避免自定义文件导入的时候要添加路径<br/>
**File --> Mark Directory as --> Sources root**
linux 下类似的命令则为:`export PYTHONPATH=$PYTHONPATH:xxxxxx`
## 目录说明:
.<br/>
├── cmm 公共功能存放该目录,例如SUID解析都需要用到<br/>
├── docs 存放开发文档、学习文档分享<br/>
├── download 下载第三方实例<br/>
├── feature 特性目录存放mongodb、mysql、zmq 通信、数据库操作模块<br/>
├── ini 存放配置文件<br/>
├── script pycharm开发环境忽略,linux方便启动conda环境,通过`source activate_env.sh`激活, 具体路径修改脚本<br/>
├── spec 规格文件存放proto定义<br/>
├── system 逻辑实现、整合, 子系统实现<br/>
├── test 存放测试代码<br/>
└── ui 该目录下的文件跟Qt Designer相关,有UI/ICON/StyleSheet<br/>
## 开发环境安装
- 1、先安装miniconda
- 2、创建基础python环境,基于3.9版本
`conda create -n xxxx python=3.9`
- 3、直接导入 requirement.txt 文件恢复库文件,该文件在script目录中
`pip install -i https://pypi.douban.com/simple/ -r requirement.txt`
- 4、pip安装包列表导出,如果有新的安装包下载到conda环境中,导出到requirement.txt文件
`pip freeze > requirement.txt`
**AES文件加密与恢复 pip install pycryptodome**
## 常用命令
- 1、设计师编辑ui文件:
designer.exe
- 2、将ui文件变为py文件
pyuic5.exe -o .\mainwindow.py .\mainwindow.ui
- 3、将qrc文件变为py文件
pyrcc5.exe -o .\image_rc.py .\image.qrc
> 两个工具在miniconda脚本目录中 C:\TOOLS\miniconda3\Scripts\pyuic5.exe
> 两个工具在miniconda脚本目录中 C:\TOOLS\miniconda3\Scripts\pyrcc5.exe
可能在其他目录,上述命令可以设置到pycharm扩展工具方便调用
## 国际化
- 1、国际化先变ts
pylupdate5.exe .\imageprocess.py -ts zh.ts
- 2、打开语言家打开ts文件完成翻译保存为qm:
linguist.exe
> 当我们的ts文件损坏或者丢失时,可以根据qm文件反生成ts文件,使用如下的命令:
lconvert compiled.qm -o source.ts
> 将多个ts文件合并输出
lconvert -i primary.ts secondary.ts -o complete.ts
import sys
import os
import configparser
from enum import Enum
class SystemID(Enum):
Server = 1
UI = 2
Device = 3
AGI = 4
OAM = 5
class ParserStartIni():
def __init__(self, path = os.getcwd()):
self.path = path
def SetIniPath(self, path):
self.path = path
def Read(self):
self.cfg = configparser.ConfigParser()
try:
self.cfg.read(self.path+"/blueocean.ini")
return True
except:
return False
def SUIDHeaderInt(self):
suid = int(self.cfg["role"]["level1"]) << 28 | int(self.cfg["role"]["level2"]) << 24 | int(self.cfg["role"]["level3"]) << 20
return suid
def LocalMqtt(self):
return [self.cfg["mqtt-local"]["server"], int(self.cfg["mqtt-local"]["port"])]
def CloudMqtt(self):
return [self.cfg["mqtt-cloud"]["server"], int(self.cfg["mqtt-cloud"]["port"])]
class ParserSUID():
def __init__(self, suid = 0):
self.suid = hex(suid)
def SetSUID(self, suid):
self.suid = hex(suid)
def GenSUID( self, suidheader, subsystem, submodule):
self.suid = hex(suidheader|subsystem<<16|submodule<<12)
def GetPubTopic(self, level):
self.suidstr = str(self.suid)
return '/'+'/'.join(str(self.suid)[2:2+level])
def GetSubTopic(self, level):
self.suidstr = str(self.suid)
return '/'+'/'.join(str(self.suid)[2:2+level])
-- MySQL dump 10.13 Distrib 8.0.28, for Linux (x86_64)
--
-- Host: 127.0.0.1 Database: blueocean
-- ------------------------------------------------------
-- Server version 8.0.28-0ubuntu0.20.04.3
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!50503 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Table structure for table `authority`
--
DROP TABLE IF EXISTS `authority`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `authority` (
`id` int NOT NULL AUTO_INCREMENT,
`authority` varchar(20) DEFAULT NULL COMMENT '权限名称',
`role` int DEFAULT NULL COMMENT '角色id',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
PRIMARY KEY (`id`),
KEY `ix_authority_role` (`role`),
KEY `ix_authority_authority` (`authority`),
CONSTRAINT `authority_ibfk_1` FOREIGN KEY (`role`) REFERENCES `role` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb3;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `authority`
--
LOCK TABLES `authority` WRITE;
/*!40000 ALTER TABLE `authority` DISABLE KEYS */;
/*!40000 ALTER TABLE `authority` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `player`
--
DROP TABLE IF EXISTS `player`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `player` (
`player_id` int NOT NULL AUTO_INCREMENT,
`team_id` int DEFAULT NULL,
`player_name` varchar(255) DEFAULT NULL COMMENT 'name',
`height` float(3,2) DEFAULT NULL,
PRIMARY KEY (`player_id`)
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `player`
--
LOCK TABLES `player` WRITE;
/*!40000 ALTER TABLE `player` DISABLE KEYS */;
INSERT INTO `player` VALUES (1,1003,' 约翰 - 科林斯 ',2.08),(2,1003,' 约翰 - 科林斯 ',2.08),(3,1003,' 约翰 - 科林斯 ',2.08),(4,1003,' 约翰 - 科林斯 ',2.08),(5,1003,' 约翰 - 科林斯 ',2.08),(6,1003,' 约翰 - 科林斯 ',2.08),(7,1003,' 约翰 - 科林斯 ',2.08),(8,1003,' 约翰 - 科林斯 ',2.08),(9,1003,' 约翰 - 科林斯 ',2.08),(10,1003,' 约翰 - 科林斯 ',2.08),(11,1003,' 约翰 - 科林斯 ',2.08),(12,1003,' 约翰 - 科林斯 ',2.08),(13,1003,' 约翰 - 科林斯 ',2.08),(14,1003,' 约翰 - 科林斯 ',2.08),(15,1003,' 约翰 - 科林斯 ',2.08),(16,1003,' 约翰 - 科林斯 ',2.08),(17,1003,' 约翰 - 科林斯 ',2.08),(18,1003,' 约翰 - 科林斯 ',2.08),(19,1003,' 约翰 - 科林斯 ',2.08);
/*!40000 ALTER TABLE `player` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `role`
--
DROP TABLE IF EXISTS `role`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `role` (
`id` int NOT NULL AUTO_INCREMENT,
`role` varchar(20) DEFAULT NULL COMMENT '角色名',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
PRIMARY KEY (`id`),
UNIQUE KEY `ix_role_role` (`role`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb3;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `role`
--
LOCK TABLES `role` WRITE;
/*!40000 ALTER TABLE `role` DISABLE KEYS */;
/*!40000 ALTER TABLE `role` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `user`
--
DROP TABLE IF EXISTS `user`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `user` (
`id` int NOT NULL AUTO_INCREMENT,
`name` varchar(20) DEFAULT NULL COMMENT '用户名',
`password` varchar(128) DEFAULT NULL COMMENT '密码',
`role` int DEFAULT NULL COMMENT '角色id',
`is_delete` tinyint(1) DEFAULT NULL COMMENT '删除标记,为True时表示可用',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`last_login` datetime NOT NULL COMMENT '最后登陆时间',
`update_time` datetime NOT NULL COMMENT '更新时间',
PRIMARY KEY (`id`),
UNIQUE KEY `ix_user_name` (`name`),
KEY `ix_user_is_delete` (`is_delete`),
KEY `ix_user_role` (`role`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb3;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `user`
--
LOCK TABLES `user` WRITE;
/*!40000 ALTER TABLE `user` DISABLE KEYS */;
/*!40000 ALTER TABLE `user` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2022-07-23 16:00:21
attention:
模块的互相包含,不在同一个目录下的模块导入。
import sys
from pathlib import Path
sys.path.append(str(Path(__file__).absolute().parent.parent) + "/spec/ormtables")
print(sys.path)
通过将模块的绝对路径加入到sys.path中才可以导入
# tables 文件名, Player 类名
from tables import Player
#数据库操作记录 ,model 类自动生成
https://blog.csdn.net/stone0823/article/details/112344065
模块的方法查看,例如Qt中的某个属性无法调用
from PyQt6.QtCore import Qt
help(Qt)
#pyqt6 和 pyside6的差异主要在许可协议上, pyside6是QT官方库,可以商业化使用
https://www.perfcode.com/p/pyside6
This source diff could not be displayed because it is too large. You can view the blob instead.
# 会议议题列表
# 会议议题列表
- python工程目录结构思路,详见Readme文档
- 针对python的编码规则,统一思路,详见python编码规则文档
- 基础库添加和使用方法案例说明等任务
- 更新requirements.txt方便其他人同步更新库版本
- 在test目录中增加相关的测试代码和README说明基本使用方法,统一规则
- 周田提到的log记录,选择loguru第三方日志库
- 王维负责mysql(pgsql)等数据库orm的使用案例和说明
- 模块设计要求
- class封装,代码复用和简化,除test代码可以流程化编写测试
- 包含typing,增强类型检查,输入参数类型,返回值类型
- dataclass创建数据类,针对属性集合,
- 多任务可使用python自带ThreadPoolExecutor比较方便管理
- 必须包含(类似C++中的处理):
- `__init__` 构造函数, 传参初始化
- `init` 函数 模块内部初始化,例如线程(生命周期等于程序)等, 变量根据__init__中的参数进行初始化
- `start` 函数 一般针对线程启动,通过信号控制,因为有时候需要各种条件准备好以后再开始
- `stop` 函数 一般针对线程退出,特别针对网络资源,socket,各种连接等的释放
- 普通成员变量 m_开头, 类变量 s_开头(静态属性)
- 编码格式基本只有两种,类名驼峰(首字母大写)、方法变量都是小写下划线,枚举全大写
- 数据库的字段名,同样也是小写下划线
- Proto文件定义,字段名也是小写下划线
- 开发流程管理
- 需求分析文档
- 任务计划表
- 概要设计文档
# Python编码规范
# Python编码规范
## 命名规则
|Python的名称类型| 示例| 注释|
|----|----|----|
|变量名| name_str| 全小写加下划线(lower_with_under)or 类的成员变量前加`m_`明确标识|
|常量名| NAME_STR| 全大写加下划线(UPPER_WITH_UNDER)|
|函数名| def convert_name():| 全小写加下划线(def lower_with_under())
|类名| class NameConvertor():| 驼峰式加首字母大写,一般是名词(class CapitalWords())|
|模块名| convert_name.py| 全小写加下划线(lower_with_under.py)|
|包名(文件夹名)| convert_name| 全小写加下划线的文件夹名称,记得必须加__init__.py文件哦(lower_with_under)|
> 变量也是小写下划线,类的成员变量前加`m_`明确标识, 类似于C++风格
其他语句代码块规则
语句代码涉及比如运算符和表达式,语句换行,tab缩进等参考Pycharm中提示的PEP8(Python 代码风格指南),有提示划线的地方都可以优化
Pycharm的:Ctrl + Alt + L 格式化代码
``` text
tip
module_name, package_name, ClassName, method_name, ExceptionName,
function_name, GLOBAL_VAR_NAME, instance_var_name,
function_parameter_name, local_var_name.
```
### !应该避免的名称
* 单字符名称, 除了计数器和迭代器.
* 包/模块名中的连字符(-)
* 双下划线开头并结尾的名称(Python保留, 例如__init__)
### 命名约定
* 所谓"内部(Internal)"表示仅模块内可用, 或者, 在类内是保护或私有的.用单下划线(_)开头表示模块变量或函数是protected的(使用import *from时不会包含).
* 用双下划线(__)开头的实例变量或方法表示类内私有.将相关的类和顶级函数放在同一个模块里. 不像Java,没必要限制一个类一个模块.
* 对类名使用大写字母开头的单词(如CapWords, 即Pascal风格),但是模块名应该用小写加下划线的方式(如lower_with_under.py).尽管已经有很多现存的模块使用类似于CapWords.py这样的命名,但现在已经不鼓励这样做, 因为如果模块名碰巧和类名一致,这会让人困扰.
## 代码注释
> 类定义或者函数注释,pycharm打开Settings->Tools->Python Integrated Tools->Docstring format 改为reStructuredText;然后在函数声明下面输入"""回车即可生成函数注释模板,如下:
```python
class ThreadExit(object):
def __init__(self):
"""
__init_ ThreadExit
"""
self.m_event = threading.Event()
self.m_thread = None
def init(self, param1, param2, param3):
"""
this is only for example~
:param param1:
:param param2:
:param param3:
:return:
"""
self.m_thread = threading.Thread(target=self.runtine)
```
## 特殊约定
* 代码一行不超过80字符,通过()隐式连接,不用反斜杠;注释可以超过。
```python
Yes: foo_bar(self, width, height, color='black', design=None, x='foo',
emphasis=None, highlight=0)
if (width == 0 and height == 0 and
color == 'red' and emphasis == 'strong'):
```
* 条件语句和返回语句中尽量不用括号,除非特别指明优先级
* 顶级定义之间空两行,函数定义之间空一行
* 类不继承其他类可以继承object基础类
* 在if __name__ == '__main__':条件下写入测试代码,如此可以避免测试代码在模块被导入后执行。
## Python之父Guido推荐的规范
|Type |Public |Internal|
| ---- | ---- |----|
|Modules| lower_with_under| _lower_with_under|
|Packages| lower_with_under||
|Classes| CapWords| _CapWords|
|Exceptions| CapWords||
|Functions| lower_with_under()| _lower_with_under()|
|Global/Class Constants| CAPS_WITH_UNDER| _CAPS_WITH_UNDER|
|Global/Class Variables| lower_with_under| _lower_with_under|
|Instance Variables| lower_with_under| _lower_with_under (protected) or __lower_with_under (private)
|Method Names| lower_with_under()| _lower_with_under() (protected) or __lower_with_under() (private)
|Function/Method| Parameters| lower_with_under|
|local Variables| lower_with_under||
\ No newline at end of file
python -c "import sys; help(sys)" > ./lib-docs/sys_help.txt
python -c "import paho.mqtt.client; help(paho.mqtt.client)" > ./lib-docs/paho_mqtt_client_help.txt
python -c "import zmq; help(zmq)" > ./lib-docs/zmq_help.txt
python -c "import sqlalchemy.orm.sessionmaker; help(sqlalchemy.orm.sessionmaker)" > ./sqlalchemy.orm.txt
[run]
plugins = Cython.Coverage
parallel = True
branch = False
omit =
zmq/eventloop/minitornado/*
zmq/tests/*
[report]
exclude_lines =
pragma: no cover
ignore_errors = True
[flake8]
exclude = .git,dist,docs,zmq/eventloop/minitornado,buildutils/templates
ignore = E, F403, F811, F841, W
per-file-ignores =
**/__init__.py:F401
.idea
.vagrant
*.pyc
zmq/backend/cython/*.c
zmq/devices/*.c
zmq/utils/*.json
zmq/include/*.h
__pycache__
build
dist
conf
bundled
libzmq-dll
*.egg-info
*.so
*.pyd
*.dll
*.dylib
docs/source/api/generated
docs/gh-pages
setup.cfg
MANIFEST
.tox
examples/security/public_keys
examples/security/private_keys
wheelhouse
.coverage
.cache
.pytest_cache
win-dist
*.pickle
.ipynb_checkpoints
venv
*.code-workspace
.vscode
.mypy_cache
.coverage
htmlcov
coverage.xml
env
.eggs
Brian E. Granger <ellisonbg@gmail.com> Brian Granger <ellisonbg@gmail.com>
Chris Laws <clawsicus@gmail.com> Chris Laws <claws@localhost>
Daniel Lundin <dln@eintr.org> Daniel Lundin <dln@spotify.com>
Min Ragan-Kelley <benjaminrk@gmail.com> Min RK <benjaminrk@gmail.com>
Min Ragan-Kelley <benjaminrk@gmail.com> MinRK <benjaminrk@gmail.com>
Michel Pelletier <pelletier.michel@gmail.com> Michel Pelletier <pelletier.michel@yahoo.com>
Nicholas Piël <nicholas@nichol.as> nicholas <nicholas@bastet.ss.sitesupport.com>
Felipe Cruz <felipecruz@loogica.net> felipecruz <felipecruz@loogica.net>
Felipe Cruz <felipecruz@loogica.net> Felipe cruz <felipecruz@loogica.net>
Yannick Hold <yannickhold@gmail.com> Yannick Hold <x_godsoul@hotmail.com>
workflow:
steps:
- link_package:
source_project: network:messaging:zeromq:git-draft
source_package: pyzmq
exclude: ^zmq/eventloop/minitornado/
repos:
- repo: https://github.com/executablebooks/mdformat
rev: 0.7.14 # Use the ref you want to point at
hooks:
- id: mdformat
# Optionally add plugins
additional_dependencies:
- mdformat-black
- mdformat-myst
- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
hooks:
- id: flake8
exclude: ^buildutils/templates/
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.961
hooks:
- id: mypy
files: zmq/.*
# mypy gets the wrong results
# if we pass specific files instead of the zmq dir
# no idea why
pass_filenames: false
args: [zmq]
additional_dependencies:
- types-paramiko
- repo: https://github.com/asottile/pyupgrade
rev: v2.37.1
hooks:
- id: pyupgrade
args:
- --py36-plus
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: isort (python)
- id: isort
name: isort (cython)
types: [cython]
- id: isort
name: isort (pyi)
types: [pyi]
- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: end-of-file-fixer
- id: check-executables-have-shebangs
- id: requirements-txt-fixer
docs/source/_templates
externals
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
version: 2
formats: all
sphinx:
configuration: docs/source/conf.py
fail_on_warning: true
python:
# https://docs.readthedocs.io/en/stable/config-file/v2.html#build-image
version: 3.7
install:
- requirements: docs/requirements.txt
- path: .
## Authors
This project was started and continues to be led by Brian E. Granger
(ellisonbg AT gmail DOT com). Min Ragan-Kelley (benjaminrk AT gmail DOT
com) is the primary developer of pyzmq at this time.
The following people have contributed to the project:
- Alexander Else (alexander DOT else AT team DOT telstra DOT com)
- Alexander Pyhalov (apyhalov AT gmail DOT com)
- Alexandr Emelin (frvzmb AT gmail DOT com)
- Amr Ali (amr AT ledgerx DOT com)
- Andre Caron (andre DOT l DOT caron AT gmail DOT com)
- Andrea Crotti (andrea DOT crotti DOT 0 AT gmail DOT com)
- Andrew Gwozdziewycz (git AT apgwoz DOT com)
- Baptiste Lepilleur (baptiste DOT lepilleur AT gmail DOT com)
- Brandyn A. White (bwhite AT dappervision DOT com)
- Brian E. Granger (ellisonbg AT gmail DOT com)
- Brian Hoffman (hoffman_brian AT bah DOT com)
- Carlos A. Rocha (carlos DOT rocha AT gmail DOT com)
- Chris Laws (clawsicus AT gmail DOT com)
- Christian Wyglendowski (christian AT bu DOT mp)
- Christoph Gohlke (cgohlke AT uci DOT edu)
- Curtis (curtis AT tinbrain DOT net)
- Cyril Holweck (cyril DOT holweck AT free DOT fr)
- Dan Colish (dcolish AT gmail DOT com)
- Daniel Lundin (dln AT eintr DOT org)
- Daniel Truemper (truemped AT googlemail DOT com)
- Douglas Creager (douglas DOT creager AT redjack DOT com)
- Eduardo Stalinho (eduardooc DOT 86 AT gmail DOT com)
- Eren Güven (erenguven0 AT gmail DOT com)
- Erick Tryzelaar (erick DOT tryzelaar AT gmail DOT com)
- Erik Tollerud (erik DOT tollerud AT gmail DOT com)
- FELD Boris (lothiraldan AT gmail DOT com)
- Fantix King (fantix DOT king AT gmail DOT com)
- Felipe Cruz (felipecruz AT loogica DOT net)
- Fernando Perez (Fernando DOT Perez AT berkeley DOT edu)
- Frank Wiles (frank AT revsys DOT com)
- Félix-Antoine Fortin (felix DOT antoine DOT fortin AT gmail DOT com)
- Gavrie Philipson (gavriep AT il DOT ibm DOT com)
- Godefroid Chapelle (gotcha AT bubblenet DOT be)
- Greg Banks (gbanks AT mybasis DOT com)
- Greg Ward (greg AT gerg DOT ca)
- Guido Goldstein (github AT a-nugget DOT de)
- Ian Lee (IanLee1521 AT gmail DOT com)
- Ionuț Arțăriși (ionut AT artarisi DOT eu)
- Ivo Danihelka (ivo AT danihelka DOT net)
- Iyed (iyed DOT bennour AT gmail DOT com)
- Jim Garrison (jim AT garrison DOT cc)
- John Gallagher (johnkgallagher AT gmail DOT com)
- Julian Taylor (jtaylor DOT debian AT googlemail DOT com)
- Justin Bronder (jsbronder AT gmail DOT com)
- Justin Riley (justin DOT t DOT riley AT gmail DOT com)
- Marc Abramowitz (marc AT marc-abramowitz DOT com)
- Matthew Aburn (mattja6 AT gmail DOT com)
- Michel Pelletier (pelletier DOT michel AT gmail DOT com)
- Michel Zou (xantares09 AT hotmail DOT com)
- Min Ragan-Kelley (benjaminrk AT gmail DOT com)
- Nell Hardcastle (nell AT dev-nell DOT com)
- Nicholas Pilkington (nicholas DOT pilkington AT gmail DOT com)
- Nicholas Piël (nicholas AT nichol DOT as)
- Nick Pellegrino (npellegrino AT mozilla DOT com)
- Nicolas Delaby (nicolas DOT delaby AT ezeep DOT com)
- Ondrej Certik (ondrej AT certik DOT cz)
- Paul Colomiets (paul AT colomiets DOT name)
- Pawel Jasinski (pawel DOT jasinski AT gmail DOT com)
- Phus Lu (phus DOT lu AT gmail DOT com)
- Robert Buchholz (rbu AT goodpoint DOT de)
- Robert Jordens (jordens AT gmail DOT com)
- Ryan Cox (ryan DOT a DOT cox AT gmail DOT com)
- Ryan Kelly (ryan AT rfk DOT id DOT au)
- Scott Maxwell (scott AT codecobblers DOT com)
- Scott Sadler (github AT mashi DOT org)
- Simon Knight (simon DOT knight AT gmail DOT com)
- Stefan Friesel (sf AT cloudcontrol DOT de)
- Stefan van der Walt (stefan AT sun DOT ac DOT za)
- Stephen Diehl (stephen DOT m DOT diehl AT gmail DOT com)
- Sylvain Corlay (scorlay AT bloomberg DOT net)
- Thomas Kluyver (takowl AT gmail DOT com)
- Thomas Spura (tomspur AT fedoraproject DOT org)
- Tigger Bear (Tigger AT Tiggers-Mac-mini DOT local)
- Torsten Landschoff (torsten DOT landschoff AT dynamore DOT de)
- Vadim Markovtsev (v DOT markovtsev AT samsung DOT com)
- Yannick Hold (yannickhold AT gmail DOT com)
- Zbigniew Jędrzejewski-Szmek (zbyszek AT in DOT waw DOT pl)
- hugo shi (hugoshi AT bleb2 DOT (none))
- jdgleeson (jdgleeson AT mac DOT com)
- kyledj (kyle AT bucebuce DOT com)
- spez (steve AT hipmunk DOT com)
- stu (stuart DOT axon AT jpcreative DOT co DOT uk)
- xantares (xantares AT fujitsu-l64 DOT (none))
as reported by:
```
git log --all --format='- %aN (%aE)' | sort -u | sed 's/@/ AT /1' | sed -e 's/\.\([^ ]\)/ DOT \1/g'
```
with some adjustments.
### Not in git log
- Brandon Craig-Rhodes (brandon AT rhodesmill DOT org)
- Eugene Chernyshov (chernyshov DOT eugene AT gmail DOT com)
- Craig Austin (craig DOT austin AT gmail DOT com)
### gevent_zeromq, now zmq.green
- Travis Cline (travis DOT cline AT gmail DOT com)
- Ryan Kelly (ryan AT rfk DOT id DOT au)
- Zachary Voase (z AT zacharyvoase DOT com)
# Testing
pyzmq is tested on GitHub Actions.
![Build Status](https://github.com/zeromq/pyzmq/actions/workflows/test.yml/badge.svg)\](https://github.com/zeromq/pyzmq/actions/workflows/test.yml)
## Opening an Issue
For a good bug report:
1. [Search] for existing Issues, both on GitHub and in general with Google/Stack Overflow before posting a duplicate question.
1. Update to pyzmq main, if possible, especially if you are already using git. It's
possible that the bug you are about to report has already been fixed.
Many things reported as pyzmq Issues are often just libzmq-related,
and don't have anything to do with pyzmq itself.
These are better directed to [zeromq-dev].
When making a bug report, it is helpful to tell us as much as you can about your system
(such as pyzmq version, libzmq version, Python version, OS Version, how you built/installed pyzmq and libzmq, etc.)
The basics:
```python
import sys
import zmq
print("libzmq-%s" % zmq.zmq_version())
print("pyzmq-%s" % zmq.pyzmq_version())
print("Python-%s" % sys.version)
```
Which will give something like:
```
libzmq-4.3.4
pyzmq-22.3.0
Python-3.9.9 | packaged by conda-forge | (main, Dec 20 2021, 02:38:53)
[Clang 11.1.0 ]
```
## Licensing and contributing to PyZMQ
PyZMQ uses different licenses for different parts of the code.
The 'core' of PyZMQ (located in zmq/core) is licensed under LGPLv3.
This just means that if you make any changes to how that code works,
you must release those changes under the LGPL.
If you just _use_ pyzmq, then you can use any license you want for your own code.
We don't feel that the restrictions imposed by the LGPL make sense for the
'non-core' functionality in pyzmq (derivative code must _also_ be LGPL or GPL),
especially for examples and utility code, so we have relicensed all 'non-core'
code under the more permissive BSD (specifically Modified BSD aka New BSD aka
3-clause BSD), where possible. This means that you can copy this code and build
your own apps without needing to license your own code with the LGPL or GPL.
### Your contributions
**Pull Requests are welcome!**
When you contribute to PyZMQ, your contributions are made under the same
license as the file you are working on. Any new, original code should be BSD
licensed.
We use [pre-commit] for autoformatting,
so you hopefully don't need to worry too much about style.
To install pre-commit:
```
pip install pre-commit
pre-commit install
```
Examples are copyright their respective authors, and BSD unless otherwise
specified by the author.
### Inherited licenses in pyzmq
Some code outside the core is taken from other open-source projects, and
inherits that project's license.
- zmq/eventloop contains files inherited and adapted from [tornado], and inherits the Apache license
- zmq/ssh/forward.py is from [paramiko], and inherits LGPL
- zmq/devices/monitoredqueue.pxd is derived from the zmq_device function in
libzmq, and inherits LGPL
- perf examples are (c) iMatix, and LGPL
[paramiko]: http://www.lag.net/paramiko
[pre-commit]: https://pre-commit.com
[search]: https://github.com/zeromq/pyzmq/issues
[tornado]: http://www.tornadoweb.org
[zeromq-dev]: mailto:zeromq-dev@zeromq.org
PyZMQ is licensed under the terms of the Modified BSD License (also known as
New or Revised BSD), as follows:
Copyright (c) 2009-2012, Brian Granger, Min Ragan-Kelley
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
Neither the name of PyZMQ nor the names of its contributors may be used to
endorse or promote products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
--------------------------------------------------------------------------------
SPECIAL EXCEPTION GRANTED BY COPYRIGHT HOLDERS
As a special exception, copyright holders give you permission to link this
library with independent modules to produce an executable, regardless of
the license terms of these independent modules, and to copy and distribute
the resulting executable under terms of your choice, provided that you also
meet, for each linked independent module, the terms and conditions of
the license of that module. An independent module is a module which is not
derived from or based on this library. If you modify this library, you must
extend this exception to your version of the library.
Note: this exception relieves you of any obligations under sections 4 and 5
of this license, and section 6 of the GNU General Public License.
include COPYING.BSD
include COPYING.LESSER
include CONTRIBUTING.md
include MANIFEST.in
include README.md
include AUTHORS.md
include setup.cfg.template
include setup.cfg.android
include setup.py
include setupegg.py
include zmqversion.py
include tox.ini
include .travis.yml
graft docs
graft tools
prune docs/build
prune docs/gh-pages
include bundled/zeromq/COPYING
graft bundled/zeromq/include
graft bundled/zeromq/src
graft bundled/zeromq/tweetnacl
graft bundled/zeromq/external/wepoll
exclude bundled/zeromq/src/Makefile*
exclude bundled/zeromq/src/platform.hpp
graft buildutils
graft examples
graft zmq
graft perf
exclude setup.cfg
exclude zmq/libzmq*
# exclude docs/_static
# exclude docs/_templates
global-exclude __pycache__/*
global-exclude .deps/*
global-exclude *.so
global-exclude *.pyd
global-exclude *.pyc
global-exclude .git*
global-exclude .DS_Store
global-exclude .mailmap
global-exclude Makefile.am
global-exclude Makefile.in
# PyZMQ: Python bindings for ØMQ
This package contains Python bindings for [ZeroMQ](https://zeromq.org).
ØMQ is a lightweight and fast messaging implementation.
PyZMQ should work with any reasonable version of Python (≥ 3.4),
as well as Python 2.7 and 3.3, as well as PyPy.
The Cython backend used by CPython supports libzmq ≥ 2.1.4 (including 3.2.x and 4.x),
but the CFFI backend used by PyPy only supports libzmq ≥ 3.2.2 (including 4.x).
For a summary of changes to pyzmq, see our
[changelog](https://pyzmq.readthedocs.io/en/latest/changelog.html).
### ØMQ 3.x, 4.x
PyZMQ fully supports the 3.x and 4.x APIs of libzmq,
developed at [zeromq/libzmq](https://github.com/zeromq/libzmq).
No code to change, no flags to pass,
just build pyzmq against the latest and it should work.
PyZMQ does not support the old libzmq 2 API on PyPy.
## Documentation
See PyZMQ's Sphinx-generated
documentation [on Read the Docs](https://pyzmq.readthedocs.io) for API
details, and some notes on Python and Cython development. If you want to
learn about using ØMQ in general, the excellent [ØMQ
Guide](http://zguide.zeromq.org/py:all) is the place to start, which has a
Python version of every example. We also have some information on our
[wiki](https://github.com/zeromq/pyzmq/wiki).
## Downloading
Unless you specifically want to develop PyZMQ, we recommend downloading
the PyZMQ source code or wheels from
[PyPI](https://pypi.io/project/pyzmq/),
or install with conda.
You can also get the latest source code from our GitHub repository, but
building from the repository will require that you install recent Cython.
## Building and installation
For more detail on building pyzmq, see [our Wiki](https://github.com/zeromq/pyzmq/wiki/Building-and-Installing-PyZMQ).
We build wheels for macOS, Windows, and Linux, so you can get a binary on those platforms with:
```
pip install pyzmq
```
but compiling from source with `pip install pyzmq` should work in most environments.
Especially on macOS, make sure you are using the latest pip (≥ 8), or it may not find the right wheels.
If the wheel doesn't work for some reason, or you want to force pyzmq to be compiled
(this is often preferable if you already have libzmq installed and configured the way you want it),
you can force installation with:
```
pip install --no-binary=:all: pyzmq
```
When compiling pyzmq (e.g. installing with pip on Linux),
it is generally recommended that zeromq be installed separately,
via homebrew, apt, yum, etc:
```
# Debian-based
sudo apt-get install libzmq3-dev
# RHEL-based
sudo yum install libzmq3-devel
```
If this is not available, pyzmq will _try_ to build libzmq as a Python Extension,
though this is not guaranteed to work.
Building pyzmq from the git repo (including release tags on GitHub) requires Cython.
## Old versions
pyzmq 16 drops support Python 2.6 and 3.2.
If you need to use one of those Python versions, you can pin your pyzmq version to before 16:
```
pip install 'pyzmq<16'
```
For libzmq 2.0.x, use 'pyzmq\<2.1'
pyzmq-2.1.11 was the last version of pyzmq to support Python 2.5,
and pyzmq ≥ 2.2.0 requires Python ≥ 2.6.
pyzmq-13.0.0 introduces PyPy support via CFFI, which only supports libzmq-3.2.2 and newer.
PyZMQ releases ≤ 2.2.0 matched libzmq versioning, but this is no longer the case,
starting with PyZMQ 13.0.0 (it was the thirteenth release, so why not?).
PyZMQ ≥ 13.0 follows semantic versioning conventions accounting only for PyZMQ itself.
# Permission to Relicense under MPLv2 or BSD
Most of pyzmq is licensed under [3-Clause BSD](https://opensource.org/licenses/BSD-3-Clause).
For historical reasons, the 'core' of pyzmq (the low-level Cython bindings)
is licensed under LGPLv3, like libzmq itself.
libzmq is in the process of moving away from LGPL to the [Mozilla Public License, version
2](https://www.mozilla.org/en-US/MPL/2.0/).
I'd like to take this opportunity to follow libzmq's example and also eliminate LGPL from pyzmq.
For a similarly copyleft license, MPLv2 can be used for the core.
However, I would prefer to update the core to follow the example of the rest of pyzmq,
and adopt the 3-Clause BSD license.
This directory collects grants from individuals and firms that hold
copyrights in pyzmq to permit licensing the pyzmq code under
the MPLv2 or BSD license. See
the [0MQ Licensing Page](http://zeromq.org/area:licensing) and
[libzmq relicensing effort](https://github.com/zeromq/libzmq/pull/1917)
for some background information.
Please create a separate file in this directory for each individual
or firm holding copyright in pyzmq core, named after the individual or
firm holding the copyright.
Each patch must be made with a GitHub handle that is clearly
associated with the copyright owner, to guarantee the identity of
the signatory. Please avoid changing the files created by other
individuals or firms granting a copyright license over their
copyrights (if rewording is required contact them and ask them to
submit an updated version). This makes it easier to verify that
the license grant was made by an authorized GitHub account.
#!/usr/bin/env python3
"""Get the authors of the LGPL-licensed subset of pyzmq (Cython bindings)"""
import re
from collections import defaultdict
from itertools import chain
from os.path import abspath, dirname, join
import git
here = dirname(__file__)
root = dirname(abspath(here))
repo = git.Repo(root)
LAST_CORE_COMMIT = 'db1d4d2f2cdd97955a7db620e667a834920a938a'
PRE_CORE_COMMIT = 'd4e3453b012962fc9bf6ed621019b395f968340c'
EXCLUDED = {
# docstring only:
'c2db4af3c591aae99bf437a223d97b30ecbfcd38',
'7b1ac07a3bbffe70af3adcd663c0cbe6f2a724f7',
'ce97f46881168c4c05d7885dc48a430c520a9683',
'14c16a97ffa95bf645ab27bf5b06c3eabda30e5e',
# accidental swapfile
'93150feb4a80712c6a379f79d561fbc87405ade8',
}
def get_all_commits():
return chain(
repo.iter_commits('master', 'zmq/backend/cython'),
repo.iter_commits(LAST_CORE_COMMIT, 'zmq/core'),
repo.iter_commits(PRE_CORE_COMMIT, ['zmq/_zmq.*']),
)
mailmap = {}
email_names = {}
pat = re.compile(r'\<([^\>]+)\>')
with open(join(root, '.mailmap')) as f:
for line in f:
if not line.strip():
continue
dest, src = pat.findall(line)
mailmap[src] = dest
email_names[dest] = line[: line.index('<')].strip()
author_commits = defaultdict(lambda: [])
for commit in get_all_commits():
# exclude some specific commits (e.g. docstring typos)
if commit.hexsha in EXCLUDED:
continue
# exclude commits that only touch generated pxi files in backend/cython
backend_cython_files = {
f for f in commit.stats.files if f.startswith('zmq/backend/cython')
}
if backend_cython_files and backend_cython_files.issubset(
{
'zmq/backend/cython/constant_enums.pxi',
'zmq/backend/cython/constants.pxi',
}
):
continue
email = commit.author.email
email = mailmap.get(email, email)
name = email_names.setdefault(email, commit.author.name)
author_commits[email].append(commit)
def sort_key(email_commits):
commits = email_commits[1]
return (len(commits), commits[0].authored_date)
for email, commits in sorted(author_commits.items(), key=sort_key, reverse=True):
if len(commits) <= 2:
msg = '{} ({})'.format(
' '.join(c.hexsha[:12] for c in commits),
commits[0].authored_datetime.year,
)
else:
msg = "{commits} commits ({start}-{end})".format(
commits=len(commits),
start=commits[-1].authored_datetime.year,
end=commits[0].authored_datetime.year,
)
print(
"- [ ] {name} {email}: {msg}".format(
name=email_names[email],
email=email,
msg=msg,
)
)
# Permission to Relicense under MPLv2 or any other OSI approved license chosen by the current PyZMQ BDFL
This is a statement by Chris Laws
that grants permission to relicense its copyrights in the Python ZeroMQ bindings
(pyzmq) under the Mozilla Public License v2 (MPLv2) or any other
Open Source Initiative approved license chosen by the current PyZMQ
BDFL (Benevolent Dictator for Life).
A portion of the commits made by the GitHub handle "claws", with
commit author "Chris Laws clawsicus@gmail.com", are copyright of Chris Laws.
This document hereby grants the pyzmq project team permission to relicense pyzmq,
including all past, present, and future contributions of the author listed above.
Chris Laws
2017/07/18
# Permission to Relicense under MPLv2 or any other OSI approved license chosen by the current PyZMQ BDFL
This is a statement by Brian E. Granger
that grants permission to relicense its copyrights in the Python ZeroMQ bindings
(pyzmq) under the Mozilla Public License v2 (MPLv2) or any other
Open Source Initiative approved license chosen by the current PyZMQ
BDFL (Benevolent Dictator for Life).
A portion of the commits made by the GitHub handle "ellisonbg", with
commit author "Brian E. Granger", are copyright of Brian E. Granger.
This document hereby grants the pyzmq project team permission to relicense pyzmq,
including all past, present, and future contributions of the author listed above.
Brian Ellison Granger
2017/07/18
This is a statement by Frank Wiles
that grants permission to relicense its copyrights in the Python ZeroMQ bindings
(pyzmq) under the Mozilla Public License v2 (MPLv2) or any other
Open Source Initiative approved license chosen by the current PyZMQ
BDFL (Benevolent Dictator for Life).
A portion of the commits made by the GitHub handle "frankwiles", with
commit author "Frank Wiles <frank@revsys.com>", are copyright of Frank Wiles .
This document hereby grants the libzmq project team to relicense pyzmq,
including all past, present and future contributions of the author listed above.
Frank Wiles
2017/07/17
# Permission to Relicense under MPLv2 or any other OSI approved license chosen by the current PyZMQ BDFL
This is a statement by Julian Taylor
that grants permission to relicense its copyrights in the Python ZeroMQ bindings
(pyzmq) under the Mozilla Public License v2 (MPLv2) or any other
Open Source Initiative approved license chosen by the current PyZMQ
BDFL (Benevolent Dictator for Life).
A portion of the commits made by the GitHub handle "juliantaylor", with
commit author "Julian Taylor <jtaylor.debian@googlemail.com>", are copyright of Julian Taylor.
This document hereby grants the libzmq project team to relicense libzmq,
including all past, present and future contributions of the author listed above.
Julian Taylor
2017/07/19
# Permission to Relicense under MPLv2 or any other OSI approved license chosen by the current PyZMQ BDFL
This is a statement by LedgerX LLC. that grants permission to relicense its copyrights in the Python ZeroMQ bindings (pyzmq) under the Mozilla Public License v2 (MPLv2).
A portion of the commits made by the GitHub handle "amrali", with commit author "Amr Ali <amr@ledgerx.com>", are copyright of LedgerX LLC. This document hereby grants the pyzmq project team permission to relicense pyzmq, including all past, present, and future contributions of the author listed above.
Amr Ali
2017/09/11
# Permission to Relicense under MPLv2 or any other OSI approved license chosen by the current PyZMQ BDFL
This is a statement by Boris Feld that grants permission to relicense its
copyrights in the Python ZeroMQ bindings (pyzmq) under the Mozilla Public
License v2 (MPLv2) or any other Open Source Initiative approved license chosen
by the current PyZMQ BDFL (Benevolent Dictator for Life).
A portion of the commits made by the GitHub handle "Lothiraldan", with commit
author "FELD Boris <lothiraldan@gmail.com>", are copyright of Boris Feld. This
document hereby grants the pyzmq project team permission to relicense pyzmq,
including all past, present, and future contributions of the author listed
above.
Boris Feld 2017/07/18
# Permission to Relicense under MPLv2 or any other OSI approved license chosen by the current PyZMQ BDFL
This is a statement by Min Ragan-Kelley
that grants permission to relicense its copyrights in the libzmq C++
library (ZeroMQ) under the Mozilla Public License v2 (MPLv2) or any other
Open Source Initiative approved license chosen by the current PyZMQ
BDFL (Benevolent Dictator for Life).
A portion of the commits made by the GitHub handle "minrk", with
commit author "Min RK benjaminrk@gmail.com", are copyright of Min Ragan-Kelley.
This document hereby grants the libzmq project team to relicense libzmq,
including all past, present and future contributions of the author listed above.
Min Ragan-Kelley
2017/07/17
# Permission to Relicense under MPLv2 or any other OSI approved license chosen by the current PyZMQ BDFL
This is a statement by Thomas Kluyver
that grants permission to relicense its copyrights in the Python ZeroMQ bindings
(pyzmq) under the Mozilla Public License v2 (MPLv2) or any other
Open Source Initiative approved license chosen by the current PyZMQ
BDFL (Benevolent Dictator for Life).
A portion of the commits made by the GitHub handle "takluyver", with
commit author "Thomas Kluyver <takowl@gmail.com>", are copyright of Thomas Kluyver.
This document hereby grants the libzmq project team to relicense libzmq,
including all past, present and future contributions of the author listed above.
Thomas Kluyver
2017/07/18
# Permission to Relicense under BSD
This is a statement by {{ name of company / name of individual }}
that grants permission to relicense its copyrights in the Python ZeroMQ bindings
(pyzmq) under the 3-Clause BSD License (BSD3).
A portion of the commits made by the Github handle "{{github username}}", with
commit author "{{github commit author}}", are copyright of {{ name }}.
This document hereby grants the pyzmq project team permission to relicense pyzmq,
including all past, present, and future contributions of the author listed above.
{{ Full Name }}
{{ creation date of document (format: yyyy/mm/dd) }}
# Permission to Relicense under MPLv2 or any other OSI approved license chosen by the current PyZMQ BDFL
This is a statement by {{ name of company / name of individual }}
that grants permission to relicense its copyrights in the Python ZeroMQ bindings
(pyzmq) under the Mozilla Public License v2 (MPLv2) or any other
Open Source Initiative approved license chosen by the current PyZMQ
BDFL (Benevolent Dictator for Life).
A portion of the commits made by the GitHub handle "{{github username}}", with
commit author "{{github commit author}}", are copyright of {{ name }} .
This document hereby grants the pyzmq project team permission to relicense pyzmq,
including all past, present, and future contributions of the author listed above.
{{ Full Name }}
{{ creation date of document (format: yyyy/mm/dd) }}
# Permission to Relicense under MPLv2
This is a statement by {{ name of company / name of individual }}
that grants permission to relicense its copyrights in the Python ZeroMQ bindings
(pyzmq) under the Mozilla Public License v2 (MPLv2).
A portion of the commits made by the GitHub handle "{{github username}}", with
commit author "{{github commit author}}", are copyright of {{ name }}.
This document hereby grants the pyzmq project team permission to relicense pyzmq,
including all past, present, and future contributions of the author listed above.
{{ Full Name }}
{{ creation date of document (format: yyyy/mm/dd) }}
# Security Policies and Procedures
This document outlines security procedures and general policies for the pyzmq project.
- [Reporting a Bug](#reporting-a-bug)
- [Disclosure Policy](#disclosure-policy)
- [Comments on this Policy](#comments-on-this-policy)
## Reporting a Bug
Thank you for improving the security of pyzmq. We appreciate your efforts and
responsible disclosure and will make every effort to acknowledge your
contributions.
Report security bugs by emailing the lead maintainer at benjaminrk AT gmail.com.
The lead maintainer will acknowledge your email as promptly as possible,
and will follow up with a more detailed response.
When the issue is confirmed, a GitHub security advisory will be created to discuss resolutions.
We will endeavor to keep you informed of the progress towards a fix and full
announcement, and may ask for additional information or guidance.
Report security bugs in libzmq itself or other packages to the mainainers of those packages.
## Disclosure Policy
When the security team receives a security bug report, they will assign it to a
primary handler. This person will coordinate the fix and release process,
involving the following steps:
- Confirm the problem and determine the affected versions.
- Audit code to find any potential similar problems.
- Prepare fixes for all releases still under maintenance. These fixes will be
released as fast as possible to npm.
## Comments on this Policy
If you have suggestions on how this process could be improved please submit a
pull request.
#e -*- mode: ruby -*-
# vi: set ft=ruby :
# This will setup a clean Ubuntu1404 LTS env
$script = <<SCRIPT
add-apt-repository ppa:fkrull/deadsnakes-python2.7
apt-get update
apt-get install -y python-pip python3-pip python-dev git htop virtualenvwrapper python2.7 python-virtualenv python-support cython \
git build-essential libtool pkg-config autotools-dev autoconf automake cmake uuid-dev libpcre3-dev valgrind \
libffi-dev
SCRIPT
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
VAGRANTFILE_LOCAL = 'Vagrantfile.local'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = 'ubuntu/trusty64'
config.vm.provision "shell", inline: $script
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--cpus", "2", "--ioapic", "on", "--memory", "512" ]
vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
end
if File.file?(VAGRANTFILE_LOCAL)
external = File.read VAGRANTFILE_LOCAL
eval external
end
end
"""utilities for building pyzmq.
Largely adapted from h5py
"""
from .bundle import *
from .config import *
from .detect import *
from .misc import *
from .msg import *
from .patch import *
#include <stdio.h>
#include <string.h>
#include "pyversion_compat.h"
#include "mutex.h"
#include "ipcmaxlen.h"
#include "zmq_compat.h"
#include <zmq.h>
typedef struct _zhint {
void *sock;
mutex_t *mutex;
size_t id;
} zhint;
void free_python_msg(void *data, void *vhint) {
zmq_msg_t msg;
zhint *hint = (zhint *)vhint;
int rc;
if (hint != NULL) {
zmq_msg_init_size(&msg, sizeof(size_t));
memcpy(zmq_msg_data(&msg), &hint->id, sizeof(size_t));
rc = mutex_lock(hint->mutex);
if (rc != 0) {
fprintf(stderr, "pyzmq-gc mutex lock failed rc=%d\n", rc);
}
rc = zmq_msg_send(&msg, hint->sock, 0);
if (rc < 0) {
/*
* gc socket could have been closed, e.g. during process teardown.
* If so, ignore the failure because there's nothing to do.
*/
if (zmq_errno() != ENOTSOCK) {
fprintf(stderr, "pyzmq-gc send failed: %s\n",
zmq_strerror(zmq_errno()));
}
}
rc = mutex_unlock(hint->mutex);
if (rc != 0) {
fprintf(stderr, "pyzmq-gc mutex unlock failed rc=%d\n", rc);
}
zmq_msg_close(&msg);
free(hint);
}
}
int zmq_wrap_msg_init_data(zmq_msg_t *msg, void *data, size_t size,
void *hint) {
return zmq_msg_init_data(msg, data, size, free_python_msg, hint);
}
import json
import os
import cffi
here = os.path.dirname(os.path.abspath(__file__))
zmq_dir = os.path.join(os.path.dirname(here), 'zmq')
backend_dir = os.path.join(zmq_dir, 'backend', 'cffi')
ffi = cffi.FFI()
def load_compiler_config():
"""load pyzmq compiler arguments"""
fname = os.path.join(zmq_dir, 'utils', 'compiler.json')
if os.path.exists(fname):
with open(fname) as f:
cfg = json.load(f)
else:
cfg = {}
cfg.setdefault("include_dirs", [])
cfg.setdefault("library_dirs", [])
cfg.setdefault("runtime_library_dirs", [])
cfg.setdefault("libraries", ["zmq"])
# cast to str, because cffi can't handle unicode paths (?!)
cfg['libraries'] = [str(lib) for lib in cfg['libraries']]
if 'zmq' not in cfg['libraries']:
cfg['libraries'].append('zmq')
for key in ("include_dirs", "library_dirs", "runtime_library_dirs"):
# interpret paths relative to parent of zmq (like source tree)
abs_paths = []
for p in cfg[key]:
if p.startswith('zmq'):
p = os.path.join(zmq_dir, p)
abs_paths.append(str(p))
cfg[key] = abs_paths
return cfg
cfg = load_compiler_config()
with open(os.path.join(backend_dir, '_cdefs.h')) as f:
ffi.cdef(f.read())
with open(os.path.join(here, "_cffi.c")) as f:
_cffi_c = f.read()
ffi.set_source(
'zmq.backend.cffi._cffi',
libraries=cfg['libraries'],
include_dirs=cfg['include_dirs'],
library_dirs=cfg['library_dirs'],
runtime_library_dirs=cfg['runtime_library_dirs'],
source=_cffi_c,
)
if __name__ == "__main__":
ffi.compile()
"""utilities for fetching build dependencies."""
# -----------------------------------------------------------------------------
# Copyright (C) PyZMQ Developers
# Distributed under the terms of the Modified BSD License.
#
# This bundling code is largely adapted from pyzmq-static's get.sh by
# Brandon Craig-Rhodes, which is itself BSD licensed.
# -----------------------------------------------------------------------------
import hashlib
import os
import platform
import shutil
import sys
import zipfile
from subprocess import PIPE, Popen
from tempfile import TemporaryDirectory
from unittest import mock
from urllib.request import urlopen
from .msg import fatal, info, warn
pjoin = os.path.join
# -----------------------------------------------------------------------------
# Constants
# -----------------------------------------------------------------------------
bundled_version = (4, 3, 4)
vs = '%i.%i.%i' % bundled_version
x, y, z = bundled_version
libzmq = "zeromq-%s.zip" % vs
download_url = f"https://github.com/zeromq/libzmq/releases/download/v{vs}"
libzmq_url = f"{download_url}/{libzmq}"
libzmq_checksum = (
"sha256:622bf650f7dab6de098c84d491052ad5a6d3e57550cd09cc259e0ab24ec83ec3"
)
HERE = os.path.dirname(__file__)
ROOT = os.path.dirname(HERE)
if platform.architecture()[0] == '64bit':
msarch = '-x64'
vcversion = 142
else:
msarch = ''
vcversion = 141
libzmq_dll = f"libzmq-v{vcversion}{msarch}-{x}_{y}_{z}.zip"
libzmq_dll_url = f"{download_url}/{libzmq_dll}"
libzmq_dll_checksums = {
"libzmq-v140-4_3_4.zip": "sha256:05b7c42fe8d5feb2795d32f71f7d900083530ee6fdd15575bfc8d1b3fb8643f7",
"libzmq-v140-x64-4_3_4.zip": "sha256:d5d75bd502d7935af3cf80734f81069be78420331c54814d0aab6d64adf450ae",
"libzmq-v141-4_3_4.zip": "sha256:acfc997f036018b8dc8ab5b3a1d1444bba6ba5621e91c756d07cd9447db19672",
"libzmq-v141-x64-4_3_4.zip": "sha256:4bb29d6fed20bd175a82317676c7e940356cd358b624efae8569c7ee11c45636",
"libzmq-v142-x64-4_3_4.zip": "sha256:61ae77d70bd55ffb85c3b30b6a4aeb40b0c69aaf492a9e691404d7f0192969e2",
}
libzmq_dll_checksum = libzmq_dll_checksums.get(libzmq_dll)
# -----------------------------------------------------------------------------
# Utilities
# -----------------------------------------------------------------------------
def untgz(archive):
return archive.replace('.tar.gz', '')
def localpath(*args):
"""construct an absolute path from a list relative to the root pyzmq directory"""
plist = [ROOT] + list(args)
return os.path.abspath(pjoin(*plist))
def checksum_file(scheme, path):
"""Return the checksum (hex digest) of a file"""
h = getattr(hashlib, scheme)()
with open(path, 'rb') as f:
chunk = f.read(65535)
while chunk:
h.update(chunk)
chunk = f.read(65535)
return h.hexdigest()
def fetch_archive(savedir, url, fname, checksum, force=False):
"""download an archive to a specific location"""
dest = pjoin(savedir, fname)
if checksum:
scheme, digest_ref = checksum.split(':')
else:
scheme = "sha256"
digest_ref = None
if os.path.exists(dest) and not force:
info("already have %s" % dest)
digest = checksum_file(scheme, fname)
if digest == digest_ref or not digest_ref:
return dest
else:
warn(f"but checksum {digest} != {digest_ref}, redownloading.")
os.remove(fname)
info(f"fetching {url} into {savedir}")
if not os.path.exists(savedir):
os.makedirs(savedir)
req = urlopen(url)
with open(dest, 'wb') as f:
f.write(req.read())
digest = checksum_file(scheme, dest)
if digest_ref and digest != digest_ref:
fatal(
"%s %s mismatch:\nExpected: %s\nActual : %s"
% (dest, scheme, digest_ref, digest)
)
elif not digest_ref:
warn(f"No digest to check, got: {scheme}:{digest}")
return dest
# -----------------------------------------------------------------------------
# libzmq
# -----------------------------------------------------------------------------
def fetch_and_extract(savedir, extract_to, url, fname, checksum):
"""Download and extract an archive"""
dest = pjoin(savedir, extract_to)
if os.path.exists(dest):
info("already have %s" % dest)
return
archive = fetch_archive(savedir, url, fname=fname, checksum=checksum)
with zipfile.ZipFile(archive) as zf:
zf.extractall(savedir)
with_version = pjoin(savedir, zf.namelist()[0])
# remove version suffix:
shutil.move(with_version, dest)
# remove archive when we are done
os.remove(archive)
def fetch_libzmq(savedir):
"""download and extract libzmq"""
fetch_and_extract(
savedir, 'zeromq', url=libzmq_url, fname=libzmq, checksum=libzmq_checksum
)
def stage_platform_hpp(zmqroot):
"""stage platform.hpp into libzmq sources
Tries ./configure first (except on Windows),
then falls back on included platform.hpp previously generated.
"""
platform_hpp = pjoin(zmqroot, 'src', 'platform.hpp')
if os.path.exists(platform_hpp):
info("already have platform.hpp")
return
if os.name == 'nt':
platform_dir = pjoin(HERE, 'include_win32')
else:
info("attempting ./configure to generate platform.hpp")
failed = False
try:
p = Popen(
["./configure", "--disable-drafts"],
cwd=zmqroot,
stdout=PIPE,
stderr=PIPE,
)
except OSError as err:
failed = True
e = str(err)
else:
o, e = p.communicate()
e = e.decode("utf8", "replace")
failed = bool(p.returncode)
if failed:
warn("failed to configure libzmq:\n%s" % e)
if sys.platform == 'darwin':
platform_dir = pjoin(HERE, 'include_darwin')
elif sys.platform.startswith('freebsd'):
platform_dir = pjoin(HERE, 'include_freebsd')
elif sys.platform.startswith('linux-armv'):
platform_dir = pjoin(HERE, 'include_linux-armv')
else:
# check for musl (alpine)
from packaging import tags
if any('musllinux' in tag.platform for tag in tags.sys_tags()):
info("Detected musllinux (likely alpine)")
platform_dir = pjoin(HERE, 'include_linux-musl')
else:
platform_dir = pjoin(HERE, 'include_linux')
else:
return
info("staging platform.hpp from: %s" % platform_dir)
shutil.copy(pjoin(platform_dir, 'platform.hpp'), platform_hpp)
def fetch_libzmq_dll(savedir):
"""Download binary release of libzmq for windows
vcversion specifies the MSVC runtime version to use
"""
dest = pjoin(savedir, 'zmq.h')
if os.path.exists(dest):
info("already have %s" % dest)
return
path = fetch_archive(
savedir, libzmq_dll_url, fname=libzmq_dll, checksum=libzmq_dll_checksum
)
archive = zipfile.ZipFile(path)
to_extract = []
for name in archive.namelist():
if not name.endswith(".exe"):
to_extract.append(name)
archive.extractall(savedir, members=to_extract)
archive.close()
def check_checksums():
"""Check all the checksums!"""
_failed = False
def less_fatal(msg):
"""Mock fatal log message to set failed flag instead of exiting
So we can see multiple failures in one run,
e.g. when updating the bundled libzmq version.
"""
warn(msg)
nonlocal _failed
_failed = True
with TemporaryDirectory() as savedir, mock.patch.dict(globals(), fatal=less_fatal):
fetch_archive(
savedir,
libzmq_url,
fname=libzmq,
checksum=libzmq_checksum,
)
for dll, checksum in libzmq_dll_checksums.items():
fetch_archive(
savedir,
f"{download_url}/{dll}",
fname=dll,
checksum=checksum,
)
if not _failed:
print("All ok!")
return _failed
if __name__ == "__main__":
# allow python -m buildutils.bundle to get bundled version
if len(sys.argv) > 1 and sys.argv[1] == "checksums":
sys.exit(check_checksums())
else:
print(vs)
#include <stdio.h>
#if defined _MSC_VER
#include <afunix.h>
#else
#include <sys/un.h>
#endif
int main(int argc, char **argv) {
struct sockaddr_un *dummy;
printf("%lu\n", sizeof(dummy->sun_path) - 1);
return 0;
}
"""Config functions"""
# -----------------------------------------------------------------------------
# Copyright (C) PyZMQ Developers
#
# This file is part of pyzmq, copied and adapted from h5py.
# h5py source used under the New BSD license
#
# h5py: <http://code.google.com/p/h5py/>
#
# Distributed under the terms of the New BSD License. The full license is in
# the file COPYING.BSD, distributed as part of this software.
# -----------------------------------------------------------------------------
import json
import os
import sys
from configparser import ConfigParser
pjoin = os.path.join
from .msg import debug, warn
# -----------------------------------------------------------------------------
# Utility functions (adapted from h5py: https://www.h5py.org/)
# -----------------------------------------------------------------------------
def load_config(name, base='conf'):
"""Load config dict from JSON"""
fname = pjoin(base, name + '.json')
if not os.path.exists(fname):
return {}
try:
with open(fname) as f:
cfg = json.load(f)
except Exception as e:
warn(f"Couldn't load {fname}: {e}")
cfg = {}
return cfg
def save_config(name, data, base='conf'):
"""Save config dict to JSON"""
if not os.path.exists(base):
os.mkdir(base)
fname = pjoin(base, name + '.json')
with open(fname, 'w') as f:
json.dump(data, f, indent=2)
def v_str(v_tuple):
"""turn (2,0,1) into '2.0.1'."""
return ".".join(str(x) for x in v_tuple)
def get_env_args():
"""Look for options in environment vars"""
settings = {}
zmq = os.environ.get("ZMQ_PREFIX")
if zmq:
debug("Found environ var ZMQ_PREFIX=%s" % zmq)
settings['zmq_prefix'] = zmq
draft_api = os.environ.get("ZMQ_DRAFT_API")
if draft_api:
debug("Found environ var ZMQ_DRAFT_API=%s" % draft_api)
settings['zmq_draft_api'] = int(draft_api)
return settings
def cfg2dict(cfg):
"""turn a ConfigParser into a nested dict
because ConfigParser objects are dumb.
"""
d = {}
for section in cfg.sections():
d[section] = dict(cfg.items(section))
return d
def get_cfg_args():
"""Look for options in setup.cfg"""
if not os.path.exists('setup.cfg'):
return {}
cfg = ConfigParser()
cfg.read('setup.cfg')
cfg = cfg2dict(cfg)
g = cfg.setdefault('global', {})
# boolean keys:
for key in [
'libzmq_extension',
'bundle_libzmq_dylib',
'no_libzmq_extension',
'have_sys_un_h',
'skip_check_zmq',
'bundle_msvcp',
]:
if key in g:
g[key] = eval(g[key])
# globals go to top level
cfg.update(cfg.pop('global'))
return cfg
def config_from_prefix(prefix):
"""Get config from zmq prefix"""
settings = {}
if prefix.lower() in ('default', 'auto', ''):
settings['zmq_prefix'] = ''
settings['libzmq_extension'] = False
settings['no_libzmq_extension'] = False
elif prefix.lower() in ('bundled', 'extension'):
settings['zmq_prefix'] = ''
settings['libzmq_extension'] = True
settings['no_libzmq_extension'] = False
else:
settings['zmq_prefix'] = os.path.abspath(prefix)
settings['libzmq_extension'] = False
settings['no_libzmq_extension'] = True
settings['allow_legacy_libzmq'] = True # explicit zmq prefix allows legacy
return settings
def merge(into, d):
"""merge two containers
into is updated, d has priority
"""
if isinstance(into, dict):
for key in d.keys():
if key not in into:
into[key] = d[key]
else:
into[key] = merge(into[key], d[key])
return into
elif isinstance(into, list):
return into + d
else:
return d
def discover_settings(conf_base=None):
"""Discover custom settings for ZMQ path"""
settings = {
'zmq_prefix': '',
'zmq_draft_api': False,
'libzmq_extension': False,
'no_libzmq_extension': False,
'skip_check_zmq': False,
'allow_legacy_libzmq': False,
'bundle_msvcp': None,
'build_ext': {},
'bdist_egg': {},
'win_ver': None,
}
if sys.platform.startswith('win'):
settings['have_sys_un_h'] = False
# target Windows version, sets WINVER, _WIN32_WINNT macros
# see https://docs.microsoft.com/en-us/cpp/porting/modifying-winver-and-win32-winnt for reference
# see https://github.com/python/cpython/blob/v3.9.1/PC/pyconfig.h#L137-L159
# for CPython's own values
if sys.version_info >= (3, 9):
# CPython 3.9 targets Windows 8 (0x0602)
settings["win_ver"] = "0x0602"
else:
# older Python, target Windows 7 (0x0601)
# CPython itself targets Vista (0x0600)
settings["win_ver"] = "0x0601"
if conf_base:
# lowest priority
merge(settings, load_config('config', conf_base))
merge(settings, get_cfg_args())
merge(settings, get_env_args())
return settings
"""
script for generating files that involve repetitive updates for zmq constants.
Run as `python setup.py constants`
Run this after updating utils/constant_names
Currently generates the following files from templates:
- constant_enums.pxi
- constants.pyi
"""
# Copyright (C) PyZMQ Developers
# Distributed under the terms of the Modified BSD License.
import enum
import os
import sys
from . import info
pjoin = os.path.join
buildutils = os.path.abspath(os.path.dirname(__file__))
root = pjoin(buildutils, os.path.pardir)
sys.path.insert(0, pjoin(root, 'zmq'))
import constants
all_names = []
for name in constants.__all__:
item = getattr(constants, name)
if isinstance(item, enum.Enum):
all_names.append(name)
ifndef_t = """#ifndef {0}
#define {0} (_PYZMQ_UNDEFINED)
#endif
"""
def no_prefix(name):
"""does the given constant have a ZMQ_ prefix?"""
return name.startswith('E') and not name.startswith('EVENT')
def cython_enums():
"""generate `enum: ZMQ_CONST` block for constant_enums.pxi"""
lines = []
for name in all_names:
if no_prefix(name):
lines.append('enum: ZMQ_{0} "{0}"'.format(name))
else:
lines.append(f'enum: ZMQ_{name}')
return dict(ZMQ_ENUMS='\n '.join(lines))
def ifndefs():
"""generate `#ifndef ZMQ_CONST` block for zmq_constants.h"""
lines = ['#define _PYZMQ_UNDEFINED (-9999)']
for name in all_names:
if not no_prefix(name):
name = 'ZMQ_%s' % name
lines.append(ifndef_t.format(name))
return dict(ZMQ_IFNDEFS='\n'.join(lines))
def promoted_constants():
"""Generate CONST: int for mypy"""
original_lines = []
with open(constants.__file__) as f:
for line in f.readlines():
original_lines.append(line)
if "AUTOGENERATED_BELOW_HERE" in line:
original_file = "".join(original_lines)
break
else:
raise ValueError("Never encountered AUTOGENERATED_BELOW_HERE")
global_assignments = []
all_lines = ["__all__: List[str] = ["]
for cls_name in dir(constants):
if cls_name.startswith("_"):
continue
cls = getattr(constants, cls_name)
if not isinstance(cls, type) or not issubclass(cls, enum.Enum):
continue
get_global_name = getattr(cls, "_global_name", lambda name: name)
all_lines.append(f' "{cls_name}",')
for key in cls.__members__:
global_name = get_global_name(key)
all_lines.append(f' "{global_name}",')
global_assignments.append(f"{global_name}: int = {cls_name}.{key}")
all_lines.append("]")
return dict(
original_file=original_file,
global_assignments="\n".join(global_assignments),
__all__="\n".join(all_lines),
)
def generate_file(fname, ns_func, dest_dir="."):
"""generate a constants file from its template"""
with open(pjoin(root, 'buildutils', 'templates', '%s' % fname)) as f:
tpl = f.read()
out = tpl.format(**ns_func())
dest = pjoin(dest_dir, fname)
info("generating %s from template" % dest)
with open(dest, 'w') as f:
f.write(out)
def render_constants():
"""render generated constant files from templates"""
generate_file(
"constant_enums.pxi", cython_enums, pjoin(root, 'zmq', 'backend', 'cython')
)
generate_file("constants.py", promoted_constants, pjoin(root, 'zmq'))
if __name__ == '__main__':
render_constants()
"""Detect zmq version"""
# -----------------------------------------------------------------------------
# Copyright (C) PyZMQ Developers
#
# This file is part of pyzmq, copied and adapted from h5py.
# h5py source used under the New BSD license
#
# h5py: <http://code.google.com/p/h5py/>
#
# Distributed under the terms of the New BSD License. The full license is in
# the file COPYING.BSD, distributed as part of this software.
# -----------------------------------------------------------------------------
import logging
import os
import platform
import shutil
import sys
from .misc import get_compiler, get_output_error
from .msg import info
from .patch import patch_lib_paths
pjoin = os.path.join
# -----------------------------------------------------------------------------
# Utility functions (adapted from h5py: https://www.h5py.org/)
# -----------------------------------------------------------------------------
def test_compilation(cfile, compiler, **compiler_attrs):
"""Test simple compilation with given settings"""
efile, ext = os.path.splitext(cfile)
cpreargs = lpreargs = []
if sys.platform == 'darwin':
# use appropriate arch for compiler
if platform.architecture()[0] == '32bit':
if platform.processor() == 'powerpc':
cpu = 'ppc'
else:
cpu = 'i386'
cpreargs = ['-arch', cpu]
lpreargs = ['-arch', cpu, '-undefined', 'dynamic_lookup']
else:
# allow for missing UB arch, since it will still work:
lpreargs = ['-undefined', 'dynamic_lookup']
if sys.platform == 'sunos5':
if platform.architecture()[0] == '32bit':
lpreargs = ['-m32']
else:
lpreargs = ['-m64']
extra = compiler_attrs.get('extra_compile_args', None)
extra_link = compiler_attrs.get('extra_link_args', [])
lpreargs.extend(extra_link)
objs = compiler.compile([cfile], extra_preargs=cpreargs, extra_postargs=extra)
compiler.link_executable(objs, efile, extra_preargs=lpreargs)
return efile
def compile_and_forget(basedir, src, compiler, **compiler_attrs):
"""Make sure src compiles and links successfully.
The resulting binary is deleted without being run.
"""
if not os.path.exists(basedir):
os.makedirs(basedir)
cfile = pjoin(basedir, os.path.basename(src))
shutil.copy(src, cfile)
try:
efile = test_compilation(cfile, compiler=compiler, **compiler_attrs)
finally:
shutil.rmtree(basedir)
def detect_zmq(basedir, compiler, **compiler_attrs):
"""Compile, link & execute a test program, in empty directory `basedir`.
The C compiler will be updated with any keywords given via setattr.
Parameters
----------
basedir : path
The location where the test program will be compiled and run
compiler : str
The distutils compiler key (e.g. 'unix', 'msvc', or 'mingw32')
**compiler_attrs : dict
Any extra compiler attributes, which will be set via ``setattr(cc)``.
Returns
-------
A dict of properties for zmq compilation, with the following two keys:
vers : tuple
The ZMQ version as a tuple of ints, e.g. (2,2,0)
settings : dict
The compiler options used to compile the test function, e.g. `include_dirs`,
`library_dirs`, `libs`, etc.
"""
cfile = pjoin(basedir, 'vers.c')
shutil.copy(pjoin(os.path.dirname(__file__), 'vers.c'), cfile)
# check if we need to link against Realtime Extensions library
if sys.platform.startswith('linux'):
info("Checking for timer_create")
info(
"** Errors about missing timer_create are a normal part of this process **"
)
if not compiler.has_function('timer_create'):
compiler_attrs['libraries'].append('rt')
info(
"** The above error about timer_create is normal and not a problem! **"
)
info("no timer_create, linking librt")
cc = get_compiler(compiler=compiler, **compiler_attrs)
efile = test_compilation(cfile, compiler=cc, **compiler_attrs)
patch_lib_paths(efile, cc.library_dirs)
# add library dirs to %PATH% for windows
env = os.environ.copy()
if sys.platform.startswith("win"):
env["PATH"] = os.pathsep.join([env["PATH"]] + cc.library_dirs)
rc, so, se = get_output_error([efile], env=env)
if rc:
msg = f"Error running version detection script:\n{so}\n{se}"
logging.error(msg)
raise OSError(msg)
handlers = {'vers': lambda val: tuple(int(v) for v in val.split('.'))}
props = {}
for line in (x for x in so.split('\n') if x):
key, val = line.split(':')
props[key] = handlers[key](val)
return props
// empty file, just to test compilation
int main(int argc, char **argv){
return 0;
}
// copied from libzmq 4.2.3
// has been removed since then
// included under LGPLv3
#ifndef __PLATFORM_HPP_INCLUDED__
#define __PLATFORM_HPP_INCLUDED__
#define ZMQ_HAVE_WINDOWS
// MSVC build configuration is controlled via options exposed in the Visual
// Studio user interface. The option to use libsodium is not exposed in the
// user interface unless a sibling `libsodium` directory to that of this
// repository exists and contains the following files:
//
// \builds\msvc\vs2015\libsodium.import.props
// \builds\msvc\vs2015\libsodium.import.xml
// additional defines required for 4.3 after this file was removed
#define ZMQ_USE_SELECT 1
#define ZMQ_POLL_BASED_ON_SELECT 1
#define ZMQ_USE_CV_IMPL_WIN32API 1
#define ZMQ_IOTHREAD_POLLER_USE_EPOLL 1
/* Have AF_UNIX sockets for ipc transport */
#define ZMQ_HAVE_IPC 1
#endif
#ifndef _stdint_h__
#define _stdint_h__
#include "../../bundled/zeromq/src/stdint.hpp"
#define UINT8_MAX 0xff
#define UINT16_MAX 0xffff
#define UINT32_MAX 0xffffffff
#define UINT64_MAX 0xffffffffffffffffull
#endif /* _stdint_h__ */
/*
This file is from pyzmq-static by Brandon Craig-Rhodes,
and used under the BSD license
py3compat from http://wiki.python.org/moin/PortingExtensionModulesToPy3k
Provide the init function that Python expects
when we compile libzmq by pretending it is a Python extension.
*/
#include "Python.h"
static PyMethodDef Methods[] = {
{NULL, NULL, 0, NULL}
};
#if PY_MAJOR_VERSION >= 3
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
"libzmq",
NULL,
-1,
Methods,
NULL,
NULL,
NULL,
NULL
};
PyMODINIT_FUNC
PyInit_libzmq(void)
{
PyObject *module = PyModule_Create(&moduledef);
return module;
}
#else // py2
PyMODINIT_FUNC
initlibzmq(void)
{
(void) Py_InitModule("libzmq", Methods);
}
#endif
"""misc build utility functions"""
# Copyright (c) PyZMQ Developers
# Distributed under the terms of the Modified BSD License.
import copy
import logging
import os
import sys
from pprint import pprint
from shlex import quote
from subprocess import PIPE, Popen
from .msg import warn
pjoin = os.path.join
def customize_mingw(cc):
# strip -mno-cygwin from mingw32 (Python Issue #12641)
for cmd in [
cc.compiler,
cc.compiler_cxx,
cc.compiler_so,
cc.linker_exe,
cc.linker_so,
]:
if '-mno-cygwin' in cmd:
cmd.remove('-mno-cygwin')
# remove problematic msvcr90
if 'msvcr90' in cc.dll_libraries:
cc.dll_libraries.remove('msvcr90')
def get_compiler(compiler, **compiler_attrs):
"""get and customize a compiler"""
cc = copy.deepcopy(compiler)
for name, val in compiler_attrs.items():
setattr(cc, name, val)
return cc
def get_output_error(cmd, **kwargs):
"""Return the exit status, stdout, stderr of a command"""
if not isinstance(cmd, list):
cmd = [cmd]
logging.debug("Running: %s", ' '.join(map(quote, cmd)))
try:
result = Popen(cmd, stdout=PIPE, stderr=PIPE, **kwargs)
except OSError as e:
return -1, '', f'Failed to run {cmd!r}: {e!r}'
so, se = result.communicate()
# unicode:
so = so.decode('utf8', 'replace')
se = se.decode('utf8', 'replace')
return result.returncode, so, se
def locate_vcredist_dir(plat):
"""Locate vcredist directory and add it to $PATH
Adding it to $PATH is required to run
executables that link libzmq to find e.g. msvcp140.dll
"""
from setuptools import msvc
vcvars = msvc.msvc14_get_vc_env(plat)
try:
vcruntime = vcvars["py_vcruntime_redist"]
except KeyError:
warn(f"platform={plat}, vcvars=")
pprint(vcvars, stream=sys.stderr)
warn(
"Failed to get py_vcruntime_redist via vcvars, may need to set it in %PATH%"
)
return None
redist_dir, dll = os.path.split(vcruntime)
# add redist dir to $PATH so that it can be found
os.environ["PATH"] += os.pathsep + redist_dir
return redist_dir
"""logging"""
# Copyright (c) PyZMQ Developers.
# Distributed under the terms of the Modified BSD License.
import logging
import os
import sys
# -----------------------------------------------------------------------------
# Logging (adapted from h5py: https://www.h5py.org/)
# -----------------------------------------------------------------------------
logger = logging.getLogger()
if os.environ.get('DEBUG'):
logger.setLevel(logging.DEBUG)
else:
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler(sys.stderr))
def debug(msg):
logger.debug(msg)
def info(msg):
logger.info(msg)
def fatal(msg, code=1):
logger.error("Fatal: " + msg)
exit(code)
def warn(msg):
logger.error("Warning: " + msg)
def line(c='*', width=48):
print(c * (width // len(c)))
"""utils for patching libraries"""
# Copyright (c) PyZMQ Developers.
# Distributed under the terms of the Modified BSD License.
import logging
import os
import re
import sys
from .misc import get_output_error
pjoin = os.path.join
# LIB_PAT from delocate
LIB_PAT = re.compile(
r"\s*(.*) \(compatibility version (\d+\.\d+\.\d+), "
r"current version (\d+\.\d+\.\d+)\)"
)
def _get_libs(fname):
rc, so, se = get_output_error(['otool', '-L', fname])
if rc:
logging.error(f"otool -L {fname} failed: {se!r}")
return
for line in so.splitlines()[1:]:
m = LIB_PAT.match(line)
if m:
yield m.group(1)
def _find_library(lib, path):
"""Find a library"""
for d in path[::-1]:
real_lib = os.path.join(d, lib)
if os.path.exists(real_lib):
return real_lib
def _install_name_change(fname, lib, real_lib):
rc, so, se = get_output_error(
['install_name_tool', '-change', lib, real_lib, fname]
)
if rc:
logging.error("Couldn't update load path: %s", se)
def patch_lib_paths(fname, library_dirs):
"""Load any weakly-defined libraries from their real location
(only on OS X)
- Find libraries with `otool -L`
- Update with `install_name_tool -change`
"""
if sys.platform != 'darwin':
return
libs = _get_libs(fname)
for lib in libs:
if not lib.startswith(('@', '/')):
real_lib = _find_library(lib, library_dirs)
if real_lib:
_install_name_change(fname, lib, real_lib)
__all__ = ['patch_lib_paths']
cdef extern from "zmq.h" nogil:
enum: PYZMQ_DRAFT_API
enum: ZMQ_VERSION
enum: ZMQ_VERSION_MAJOR
enum: ZMQ_VERSION_MINOR
enum: ZMQ_VERSION_PATCH
{ZMQ_ENUMS}
{original_file}
{global_assignments}
{__all__}
// check libzmq version
#include <stdio.h>
#include "zmq.h"
int main(int argc, char **argv){
int major, minor, patch;
zmq_version(&major, &minor, &patch);
fprintf(stdout, "vers: %d.%d.%d\n", major, minor, patch);
return 0;
}
comment: off
# show coverage in CI status, but never consider it a failure
coverage:
status:
project:
default:
target: 0%
patch:
default:
target: 0%
# Makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = build
SRCDIR = source
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) $(SRCDIR)
.PHONY: help clean html dirhtml pickle json htmlhelp qthelp latex changes linkcheck doctest
default: html
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
clean:
-rm -rf $(BUILDDIR)/*
-rm -rf $(SRCDIR)/api/generated/*
-rm -rf dist
-rm -rf gh-pages
api: $(SRCDIR)/api/generated/gen.rst
$(SRCDIR)/api/generated/gen.rst:
python autogen_api.py
@echo "Build API docs finished."
dist: all
mkdir -p dist
rm -rf dist/*
ln $(BUILDDIR)/latex/PyZMQ.pdf dist/
cp -a $(BUILDDIR)/html dist/
@echo "Build finished. Final docs are in dist/"
pdf: latex
cd $(BUILDDIR)/latex && make all-pdf
all: html pdf
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."
json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."
htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."
qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/PyZMQ.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/PyZMQ.qhc"
latex: api
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make all-pdf' or \`make all-ps' in that directory to" \
"run these through (pdf)latex."
changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."
linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."
doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."
gh-pages: html
sh update_ghpages.sh
#!/usr/bin/env python
"""Script to auto-generate our API docs.
"""
# stdlib imports
import os
import sys
# local imports
sys.path.append(os.path.abspath('sphinxext'))
# import sphinx_cython
from apigen import ApiDocWriter
# *****************************************************************************
if __name__ == '__main__':
pjoin = os.path.join
package = 'zmq'
outdir = pjoin('source', 'api', 'generated')
docwriter = ApiDocWriter(package, rst_extension='.rst')
# You have to escape the . here because . is a special char for regexps.
# You must do make clean if you change this!
docwriter.package_skip_patterns += [
r'\.tests$',
r'\.backend$',
r'\.auth$',
r'\.eventloop\.minitornado$',
r'\.green\.eventloop$',
r'\.sugar$',
r'\.devices$',
]
docwriter.module_skip_patterns += [
r'\.eventloop\.stack_context$',
r'\.eventloop\.future$',
r'\.error$',
r'\.green\..+$',
r'\.utils\.initthreads$',
r'\.utils\.constant_names$',
r'\.utils\.garbage$',
r'\.utils\.rebuffer$',
r'\.utils\.strtypes$',
r'\.zmq$',
]
# Now, generate the outputs
docwriter.write_api_docs(outdir)
docwriter.write_index(outdir, 'gen', relative_to=pjoin('source', 'api'))
print('%d files written' % len(docwriter.written_modules))
cython>=0.29
enum-tools[sphinx]>=0.9
gevent
myst-parser[linkify]
pydata_sphinx_theme
pygments>=2.6
sphinx>=3.0.4
sphinx-rtd-theme==0.5.*
tornado
{% extends "!layout.html" %}
{% block rootrellink %}
<li><a href="{{ pathto('index') }}">home</a>|&nbsp;</li>
<li><a href="{{ pathto('search') }}">search</a>|&nbsp;</li>
<li><a href="{{ pathto('api/index') }}">API</a> &raquo;</li>
{% endblock %}
{% block relbar1 %}
<div style="background-color: white; text-align: left; padding: 10px 10px 15px 15px">
<a href="{{ pathto('index') }}"><img src="{{
pathto("_static/logo.png", 1) }}" border="0" alt="PyZMQ Documentation"/></a>
</div>
{{ super() }}
{% endblock %}
{# put the sidebar before the body #}
{% block sidebar1 %}{{ sidebar() }}{% endblock %}
{% block sidebar2 %}{% endblock %}
.. _api-index:
###################
The PyZMQ API
###################
:Release: |release|
:Date: |today|
.. toctree::
zmq
zmq.devices
zmq.decorators
zmq.green
zmq.eventloop.ioloop
zmq.eventloop.future
zmq.asyncio
zmq.eventloop.zmqstream
zmq.auth
zmq.auth.asyncio
zmq.auth.thread
zmq.auth.ioloop
zmq.log.handlers
zmq.ssh.tunnel
zmq.utils.jsonapi
zmq.utils.monitor
zmq.utils.z85
zmq.utils.win32
.. AUTO-GENERATED FILE -- DO NOT EDIT!
asyncio
=======
Module: :mod:`zmq.asyncio`
--------------------------
.. automodule:: zmq.asyncio
.. currentmodule:: zmq.asyncio
.. versionadded:: 15.0
As of 15.0, pyzmq now supports :mod:`asyncio`, via :mod:`zmq.asyncio`.
When imported from this module, blocking methods such as
:meth:`zmq.asyncio.Socket.recv_multipart`, :meth:`zmq.asyncio.Socket.poll`,
and :meth:`zmq.asyncio.Poller.poll` return :class:`~.asyncio.Future` s.
.. sourcecode:: python
import asyncio
import zmq
import zmq.asyncio
ctx = zmq.asyncio.Context()
async def recv_and_process():
sock = ctx.socket(zmq.PULL)
sock.bind(url)
msg = await sock.recv_multipart() # waits for msg to be ready
reply = await async_process(msg)
await sock.send_multipart(reply)
asyncio.run(recv_and_process())
Classes
-------
:class:`ZMQEventLoop`
~~~~~~~~~~~~~~~~~~~~~
.. autoclass:: ZMQEventLoop
:class:`Context`
~~~~~~~~~~~~~~~~
Context class that creates Future-returning sockets. See :class:`zmq.Context` for more info.
.. autoclass:: Context
:noindex:
:class:`Socket`
~~~~~~~~~~~~~~~
Socket subclass that returns :class:`asyncio.Future` s from blocking methods,
for use in coroutines and async applications.
.. seealso::
:class:`zmq.Socket` for the inherited API.
.. autoclass:: Socket
:noindex:
.. automethod:: recv
:noindex:
.. automethod:: recv_multipart
:noindex:
.. automethod:: send
:noindex:
.. automethod:: send_multipart
:noindex:
.. automethod:: poll
:noindex:
:class:`Poller`
~~~~~~~~~~~~~~~
Poller subclass that returns :class:`asyncio.Future` s from poll,
for use in coroutines and async applications.
.. seealso::
:class:`zmq.Poller` for the inherited API.
.. autoclass:: Poller
:noindex:
.. automethod:: poll
:noindex:
auth.asyncio
============
Module: :mod:`auth.asyncio`
---------------------------
.. automodule:: zmq.auth.asyncio
.. currentmodule:: zmq.auth.asyncio
Classes
-------
:class:`AsyncioAuthenticator`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. autoclass:: AsyncioAuthenticator
:members:
:undoc-members:
:inherited-members:
.. AUTO-GENERATED FILE -- DO NOT EDIT!
auth.ioloop
===========
Module: :mod:`auth.ioloop`
--------------------------
.. automodule:: zmq.auth.ioloop
:noindex:
.. currentmodule:: zmq.auth.ioloop
:class:`IOLoopAuthenticator`
----------------------------
.. autoclass:: IOLoopAuthenticator
:members:
:undoc-members:
:inherited-members:
auth
====
Module: :mod:`auth`
-------------------
.. automodule:: zmq.auth
.. currentmodule:: zmq.auth
:class:`Authenticator`
----------------------
.. autoclass:: Authenticator
:members:
:undoc-members:
:inherited-members:
Functions
---------
.. autofunction:: create_certificates
.. autofunction:: load_certificate
.. autofunction:: load_certificates
.. AUTO-GENERATED FILE -- DO NOT EDIT!
auth.thread
===========
Module: :mod:`auth.thread`
--------------------------
.. automodule:: zmq.auth.thread
.. currentmodule:: zmq.auth.thread
Classes
-------
:class:`ThreadAuthenticator`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. autoclass:: ThreadAuthenticator
:members:
:undoc-members:
:inherited-members:
decorators
==========
Module: :mod:`zmq.decorators`
-----------------------------
.. automodule:: zmq.decorators
.. currentmodule:: zmq.decorators
Decorators
----------
.. autofunction:: zmq.decorators.context
.. autofunction:: zmq.decorators.socket
devices
=======
Functions
---------
.. autofunction:: zmq.device
:noindex:
.. autofunction:: zmq.proxy
:noindex:
.. autofunction:: zmq.proxy_steerable
:noindex:
Module: :mod:`zmq.devices`
--------------------------
.. automodule:: zmq.devices
.. currentmodule:: zmq.devices
Base Devices
------------
:class:`Device`
***************
.. autoclass:: Device
:members:
:exclude-members: context_factory, run, run_device
:class:`ThreadDevice`
*********************
.. autoclass:: ThreadDevice
:members:
:class:`ProcessDevice`
**********************
.. autoclass:: ProcessDevice
:members:
Proxy Devices
-------------
:class:`Proxy`
**************
.. autoclass:: Proxy
:members: bind_mon, connect_mon, setsockopt_mon
:class:`ThreadProxy`
********************
.. autoclass:: ThreadProxy
:members:
:class:`ProcessProxy`
*********************
.. autoclass:: ProcessProxy
:members:
:class:`ProxySteerable`
***********************
.. autoclass:: ProxySteerable
:members: bind_ctrl, connect_ctrl, setsockopt_ctrl
:class:`ThreadProxySteerable`
*****************************
.. autoclass:: ThreadProxySteerable
:members:
:class:`ProcessProxySteerable`
******************************
.. autoclass:: ProcessProxySteerable
:members:
MonitoredQueue Devices
----------------------
.. autofunction:: zmq.devices.monitored_queue
:class:`MonitoredQueue`
***********************
.. autoclass:: MonitoredQueue
:members:
:class:`ThreadMonitoredQueue`
*****************************
.. autoclass:: ThreadMonitoredQueue
:members:
:class:`ProcessMonitoredQueue`
******************************
.. autoclass:: ProcessMonitoredQueue
:members:
.. AUTO-GENERATED FILE -- DO NOT EDIT!
eventloop.future
================
Module: :mod:`eventloop.future`
-------------------------------
.. automodule:: zmq.eventloop.future
.. currentmodule:: zmq.eventloop.future
.. versionadded:: 15.0
As of pyzmq 15, there is a new Socket subclass that returns Futures for recv methods,
which can be found at :class:`zmq.eventloop.future.Socket`.
You can create these sockets by instantiating a :class:`~zmq.eventloop.future.Context`
from the same module.
These sockets let you easily use zmq with tornado's coroutines.
.. seealso::
:mod:`tornado.gen`
.. sourcecode:: python
from tornado import gen
from zmq.eventloop.future import Context
ctx = Context()
@gen.coroutine
def recv_and_process():
sock = ctx.socket(zmq.PULL)
sock.bind(url)
msg = yield sock.recv_multipart() # waits for msg to be ready
reply = yield async_process(msg)
yield sock.send_multipart(reply)
Classes
-------
:class:`Context`
~~~~~~~~~~~~~~~~
Context class that creates Future-returning sockets. See :class:`zmq.Context` for more info.
.. autoclass:: Context
:noindex:
:class:`Socket`
~~~~~~~~~~~~~~~
Socket subclass that returns :class:`~tornado.concurrent.Future` s from blocking methods,
for use in coroutines and async applications.
.. seealso::
:class:`zmq.Socket` for the inherited API.
.. autoclass:: Socket
:noindex:
.. automethod:: recv
:noindex:
.. automethod:: recv_multipart
:noindex:
.. automethod:: send
:noindex:
.. automethod:: send_multipart
:noindex:
.. automethod:: poll
:noindex:
:class:`Poller`
~~~~~~~~~~~~~~~
Poller subclass that returns :class:`~tornado.concurrent.Future` s from poll,
for use in coroutines and async applications.
.. seealso::
:class:`zmq.Poller` for the inherited API.
.. autoclass:: Poller
:noindex:
.. automethod:: poll
:noindex:
eventloop.ioloop
================
Module: :mod:`eventloop.ioloop`
-------------------------------
.. automodule:: zmq.eventloop.ioloop
.. currentmodule:: zmq.eventloop.ioloop
Classes
-------
:class:`ZMQIOLoop`
~~~~~~~~~~~~~~~~~~
.. autoclass:: ZMQIOLoop
Function
--------
.. autofunction:: zmq.eventloop.ioloop.install
.. AUTO-GENERATED FILE -- DO NOT EDIT!
eventloop.zmqstream
===================
Module: :mod:`eventloop.zmqstream`
----------------------------------
.. automodule:: zmq.eventloop.zmqstream
.. currentmodule:: zmq.eventloop.zmqstream
:class:`ZMQStream`
------------------
.. autoclass:: ZMQStream
:members:
:undoc-members:
:inherited-members:
green
=====
Module: :mod:`green`
--------------------
.. automodule:: zmq.green
.. AUTO-GENERATED FILE -- DO NOT EDIT!
log.handlers
============
Module: :mod:`log.handlers`
---------------------------
.. automodule:: zmq.log.handlers
.. currentmodule:: zmq.log.handlers
Classes
-------
:class:`PUBHandler`
~~~~~~~~~~~~~~~~~~~
.. autoclass:: PUBHandler
:members:
:undoc-members:
:inherited-members:
:class:`TopicLogger`
~~~~~~~~~~~~~~~~~~~~
.. autoclass:: TopicLogger
:members:
:undoc-members:
:inherited-members:
zmq
===
.. automodule:: zmq
.. currentmodule:: zmq
Basic Classes
-------------
:class:`Context`
****************
.. autoclass:: Context
:members:
:inherited-members:
:exclude-members: sockopts, closed, __del__, __enter__, __exit__, __copy__, __deepcopy__, __delattr__, __getattr__, __setattr__,
.. attribute:: closed
boolean - whether the context has been terminated.
If True, you can no longer use this Context.
:class:`Socket`
***************
.. autoclass:: Socket
:members:
:inherited-members:
:exclude-members: closed, context, getsockopt_unicode, recv_unicode, setsockopt_unicode, send_unicode, __del__, __enter__, __exit__, __copy__, __deepcopy__, __delattr__, __getattr__, __setattr__,
.. attribute:: closed
boolean - whether the socket has been closed.
If True, you can no longer use this Socket.
.. attribute:: copy_threshold
integer - size (in bytes) below which messages
should always be copied.
Zero-copy support has nontrivial overhead
due to the need to coordinate garbage collection
with the libzmq IO thread,
so sending small messages (typically < 10s of kB)
with ``copy=False`` is often more expensive
than with ``copy=True``.
The initial default value is 65536 (64kB),
a reasonable default based on testing.
Defaults to :const:`zmq.COPY_THRESHOLD` on socket construction.
Setting :const:`zmq.COPY_THRESHOLD` will define the default
value for any subsequently created sockets.
.. versionadded:: 17
:class:`Frame`
**************
.. autoclass:: Frame
:members:
:inherited-members:
:class:`MessageTracker`
***********************
.. autoclass:: MessageTracker
:members:
:inherited-members:
Polling
-------
:class:`Poller`
***************
.. autoclass:: Poller
:members:
:inherited-members:
.. autofunction:: zmq.select
Constants
---------
All libzmq constants are available as top-level attributes
(``zmq.PUSH``, etc.),
as well as via enums (``zmq.SocketType.PUSH``, etc.).
.. versionchanged:: 23
constants for unavailable socket types
or draft features will always be defined in pyzmq,
whether the features themselves are available or not.
.. versionadded:: 23
Each category of zmq constant is now available as an IntEnum.
.. autoenum:: SocketType
.. autoenum:: SocketOption
.. autoenum:: Flag
.. autoenum:: PollEvent
.. autoenum:: ContextOption
.. autoenum:: MessageOption
.. autoenum:: Event
.. autoenum:: SecurityMechanism
.. autoenum:: DeviceType
.. autoenum:: Errno
Exceptions
----------
:class:`ZMQError`
*****************
.. autoclass:: ZMQError
:members:
:inherited-members:
:class:`ZMQVersionError`
************************
.. autoclass:: ZMQVersionError
:members:
:inherited-members:
:class:`Again`
**************
.. autoclass:: Again
:class:`ContextTerminated`
**************************
.. autoclass:: ContextTerminated
:class:`NotDone`
****************
.. autoclass:: NotDone
:class:`ZMQBindError`
*********************
.. autoclass:: ZMQBindError
Functions
---------
.. autofunction:: zmq.zmq_version
.. autofunction:: zmq.pyzmq_version
.. autofunction:: zmq.zmq_version_info
.. autofunction:: zmq.pyzmq_version_info
.. autofunction:: zmq.has
.. autofunction:: zmq.device
.. autofunction:: zmq.proxy
.. autofunction:: zmq.proxy_steerable
.. autofunction:: zmq.curve_public
.. autofunction:: zmq.curve_keypair
.. autofunction:: zmq.get_includes
.. autofunction:: zmq.get_library_dirs
.. AUTO-GENERATED FILE -- DO NOT EDIT!
ssh.tunnel
==========
Module: :mod:`ssh.tunnel`
-------------------------
.. automodule:: zmq.ssh.tunnel
.. currentmodule:: zmq.ssh.tunnel
Functions
---------
.. autofunction:: zmq.ssh.tunnel.open_tunnel
.. autofunction:: zmq.ssh.tunnel.openssh_tunnel
.. autofunction:: zmq.ssh.tunnel.paramiko_tunnel
.. autofunction:: zmq.ssh.tunnel.select_random_ports
.. autofunction:: zmq.ssh.tunnel.try_passwordless_ssh
.. autofunction:: zmq.ssh.tunnel.tunnel_connection
.. AUTO-GENERATED FILE -- DO NOT EDIT!
utils.jsonapi
=============
Module: :mod:`utils.jsonapi`
----------------------------
.. automodule:: zmq.utils.jsonapi
.. currentmodule:: zmq.utils.jsonapi
Functions
---------
.. autofunction:: zmq.utils.jsonapi.dumps
.. autofunction:: zmq.utils.jsonapi.loads
.. AUTO-GENERATED FILE -- DO NOT EDIT!
utils.monitor
=============
Module: :mod:`utils.monitor`
----------------------------
.. automodule:: zmq.utils.monitor
.. currentmodule:: zmq.utils.monitor
Functions
---------
.. autofunction:: zmq.utils.monitor.parse_monitor_message
.. autofunction:: zmq.utils.monitor.recv_monitor_message
utils.win32
===========
Module: :mod:`zmq.utils.win32`
------------------------------
.. automodule:: zmq.utils.win32
.. currentmodule:: zmq.utils.win32
:class:`allow_interrupt`
------------------------
.. autoclass:: allow_interrupt
.. AUTO-GENERATED FILE -- DO NOT EDIT!
utils.z85
=========
Module: :mod:`utils.z85`
------------------------
.. automodule:: zmq.utils.z85
.. currentmodule:: zmq.utils.z85
Functions
---------
.. autofunction:: zmq.utils.z85.decode
.. autofunction:: zmq.utils.z85.encode
#
# PyZMQ documentation build configuration file, created by
# sphinx-quickstart on Sat Feb 20 23:31:19 2010.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import os
import sys
# add repo root to sys.path
here = os.path.dirname(__file__)
sys.path.append(os.path.abspath(os.path.join(here, os.pardir, os.pardir)))
# set target libzmq version
from buildutils.bundle import bundled_version
target_libzmq = '%i.%i.%i' % bundled_version
# -- General configuration -----------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.intersphinx',
'sphinx.ext.napoleon',
'sphinx_rtd_theme',
'myst_parser',
'enum_tools.autoenum',
]
myst_enable_extensions = [
"colon_fence",
"linkify",
"smartquotes",
"substitution",
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = ['.md', '.rst']
# The encoding of source files.
source_encoding = 'utf-8'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = 'PyZMQ'
copyright = """Brian E. Granger & Min Ragan-Kelley.
ØMQ logo © iMatix Corporation, used under the Creative Commons Attribution-Share Alike 3.0 License.
Python logo ™ of the Python Software Foundation, used by Min RK with permission from the Foundation"""
intersphinx_mapping = {
'python': ('https://docs.python.org/3', None),
'tornado': ('https://www.tornadoweb.org/en/stable', None),
}
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
import zmq
# The short X.Y version.
version = '.'.join(zmq.__version__.split('.')[:2])
# The full version, including alpha/beta/rc tags.
release = zmq.__version__
myst_substitutions = {
"version": version,
"release": release,
"target_libzmq": target_libzmq,
}
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
# language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
# today = ''
# Else, today_fmt is used as the format for a strftime call.
# today_fmt = '%B %d, %Y'
# List of documents that shouldn't be included in the build.
# unused_docs = []
# List of directories, relative to source directory, that shouldn't be searched
# for source files.
exclude_trees = ['build']
# The reST default role (used for this markup: `text`) to use for all documents.
default_role = 'literal'
# If true, '()' will be appended to :func: etc. cross-reference text.
# add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
# add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
# show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []
# List of Sphinx warnings that will not be raised
suppress_warnings = ['epub.unknown_project_files']
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. Major themes that come with
# Sphinx are currently 'default' and 'sphinxdoc'.
html_theme = "pydata_sphinx_theme"
# html_logo = "_static/logo.png"
html_theme_options = {
"icon_links": [
{
# Label for this link
"name": "PyZMQ on GitHub",
"url": "https://github.com/zeromq/pyzmq",
"icon": "fab fa-github-square",
}
]
}
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
# html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
# html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
# html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
# html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
# html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
html_favicon = '_static/zeromq.ico'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
# html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
# html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
# html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
# html_additional_pages = {}
# If false, no module index is generated.
# html_use_modindex = True
# If false, no index is generated.
# html_use_index = True
# If true, the index is split into individual pages for each letter.
# html_split_index = False
# If true, links to the reST sources are added to the pages.
# html_show_sourcelink = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
# html_use_opensearch = ''
# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
# html_file_suffix = ''
# Output file base name for HTML help builder.
htmlhelp_basename = 'PyZMQdoc'
# -- Options for LaTeX output --------------------------------------------------
# The paper size ('letter' or 'a4').
# latex_paper_size = 'letter'
# The font size ('10pt', '11pt' or '12pt').
# latex_font_size = '10pt'
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
(
'index',
'PyZMQ.tex',
'PyZMQ Documentation',
'Brian E. Granger \\and Min Ragan-Kelley',
'manual',
),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
# latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
# latex_use_parts = False
# Additional stuff for the LaTeX preamble.
# latex_preamble = ''
# Documents to append as an appendix to all manuals.
# latex_appendices = []
# If false, no module index is generated.
# latex_use_modindex = True
% PyZMQ devices doc, by Min Ragan-Kelley, 2011
(devices)=
# Devices in PyZMQ
```{seealso}
ØMQ Guide [Device coverage](https://zguide.zeromq.org/docs/chapter2/#ZeroMQ-s-Built-In-Proxy-Function).
```
ØMQ has a notion of Devices - simple programs that manage a send-recv pattern for
connecting two or more sockets. Being full programs, devices include a `while(True)`
loop and thus block execution permanently once invoked. We have provided in the
{mod}`devices` subpackage some facilities for running these devices in the background, as
well as a custom three-socket [MonitoredQueue](monitored-queue) device.
## BackgroundDevices
It seems fairly rare that in a Python program one would actually want to create a zmq
device via {func}`.device` in the main thread, since such a call would block execution
forever. The most likely model for launching devices is in background threads or
processes. We have provided classes for launching devices in a background thread with
{class}`.ThreadDevice` and via multiprocessing with {class}`.ProcessDevice`. For
threadsafety and running across processes, these methods do not take Socket objects as
arguments, but rather socket types, and then the socket creation and configuration happens
via the BackgroundDevice's {meth}`foo_in` proxy methods. For each configuration method
(bind/connect/setsockopt), there are proxy methods for calling those methods on the Socket
objects created in the background thread or process, prefixed with 'in\_' or 'out\_',
corresponding to the `in_socket` and `out_socket`:
```
from zmq.devices import ProcessDevice
pd = ProcessDevice(zmq.QUEUE, zmq.ROUTER, zmq.DEALER)
pd.bind_in('tcp://*:12345')
pd.connect_out('tcp://127.0.0.1:12543')
pd.setsockopt_in(zmq.IDENTITY, 'ROUTER')
pd.setsockopt_out(zmq.IDENTITY, 'DEALER')
pd.start()
# it will now be running in a background process
```
(monitored-queue)=
## MonitoredQueue
One of ØMQ's builtin devices is the `QUEUE`. This is a symmetric two-socket device that
fully supports passing messages in either direction via any pattern. We saw a logical
extension of the `QUEUE` as one that behaves in the same way with respect to the in/out
sockets, but also sends every message in either direction *also* on a third `monitor`
socket. For performance reasons, this {func}`.monitored_queue` function is written in
Cython, so the loop does not involve Python, and should have the same performance as the
basic `QUEUE` device.
One shortcoming of the `QUEUE` device is that it does not support having `ROUTER`
sockets as both input and output. This is because `ROUTER` sockets, when they receive a
message, prepend the `IDENTITY` of the socket that sent the message (for use in routing
the reply). The result is that the output socket will always try to route the incoming
message back to the original sender, which is presumably not the intended pattern. In
order for the queue to support a ROUTER-ROUTER connection, it must swap the first two parts
of the message in order to get the right message out the other side.
To invoke a monitored queue is similar to invoking a regular ØMQ device:
```
from zmq.devices import monitored_queue
ins = ctx.socket(zmq.ROUTER)
outs = ctx.socket(zmq.DEALER)
mons = ctx.socket(zmq.PUB)
configure_sockets(ins,outs,mons)
monitored_queue(ins, outs, mons, in_prefix='in', out_prefix='out')
```
The `in_prefix` and `out_prefix` default to 'in' and 'out' respectively, and a PUB socket
is most logical for the monitor socket, since it will never receive messages, and the
in/out prefix is well suited to the PUB/SUB topic subscription model. All messages sent on
`mons` will be multipart, the first part being the prefix corresponding to the socket that
received the message.
Or for launching an MQ in the background, there are {class}`.ThreadMonitoredQueue` and
{class}`.ProcessMonitoredQueue`, which function just like the base
BackgroundDevice objects, but add {meth}`foo_mon` methods for configuring the monitor socket.
(draft)=
# Working with libzmq DRAFT sockets
libzmq-4.2 has introduced the concept of unstable DRAFT APIs.
As of libzmq-4.2, this includes the CLIENT-SERVER and RADIO-DISH patterns.
Because these APIs are explicitly unstable,
pyzmq does not support them by default,
and pyzmq binaries (wheels) will not be built with DRAFT API support.
However, pyzmq-17 can be built with draft socket support,
as long as you compile pyzmq yourself with a special flag.
To install libzmq with draft support:
```bash
ZMQ_VERSION=4.3.4
PREFIX=/usr/local
wget https://github.com/zeromq/libzmq/releases/download/v${ZMQ_VERSION}/zeromq-${ZMQ_VERSION}.tar.gz -O libzmq.tar.gz
tar -xzf libzmq.tar.gz
cd zeromq-${ZMQ_VERSION}
./configure --prefix=${PREFIX} --enable-drafts
make -j && make install
```
And to install pyzmq with draft support:
```bash
export ZMQ_PREFIX=${PREFIX}
export ZMQ_DRAFT_API=1
pip install -v --no-binary pyzmq --pre pyzmq
```
By specifying `--no-binary pyzmq`, pip knows to not install wheels, and will compile pyzmq from source.
The `ZMQ_PREFIX=$PREFIX` part is only necessary if libzmq is installed somewhere not on the default search path.
If libzmq is installed in {file}`/usr/local` or similar,
only the `ZMQ_ENABLE_DRAFTS` option is required.
There are examples of the CLIENT-SERVER and RADIO-DISH patterns in the {file}`examples/draft`
directory of the pyzmq repository.
(eventloop)=
# Eventloops and PyZMQ
As of pyzmq 17, integrating pyzmq with eventloops should work without any pre-configuration.
Due to the use of an edge-triggered file descriptor,
this has been known to have issues, so please report problems with eventloop integration.
(asyncio)=
## AsyncIO
PyZMQ 15 adds support for {mod}`asyncio` via {mod}`zmq.asyncio`, containing a Socket subclass
that returns {py:class}`asyncio.Future` objects for use in {py:mod}`asyncio` coroutines.
To use this API, import {class}`zmq.asyncio.Context`.
Sockets created by this Context will return Futures from any would-be blocking method.
```python
import asyncio
import zmq
from zmq.asyncio import Context
ctx = Context.instance()
async def recv():
s = ctx.socket(zmq.SUB)
s.connect("tcp://127.0.0.1:5555")
s.subscribe(b"")
while True:
msg = await s.recv_multipart()
print("received", msg)
s.close()
```
````{note}
In PyZMQ \< 17, an additional step is needed to register the zmq poller prior to starting any async code:
```python
import zmq.asyncio
zmq.asyncio.install()
ctx = zmq.asyncio.Context()
```
This step is no longer needed in pyzmq 17.
````
## Tornado IOLoop
[Tornado] includes an eventloop for handing poll events on filedescriptors and
native sockets. We have included a small part of Tornado (specifically its
{mod}`.ioloop`), and adapted its {class}`IOStream` class into {class}`.ZMQStream` for
handling poll events on ØMQ sockets. A ZMQStream object works much like a Socket object,
but instead of calling {meth}`~.Socket.recv` directly, you register a callback with
{meth}`~.ZMQStream.on_recv`. Callbacks can also be registered for send events
with {meth}`~.ZMQStream.on_send`.
(futures)=
### Futures and coroutines
```{note}
With recent Python (3.6) and tornado (5),
there's no reason to use {mod}`zmq.eventloop.future`
instead of the strictly-more-compatible {mod}`zmq.asyncio`.
```
PyZMQ 15 adds {mod}`zmq.eventloop.future`, containing a Socket subclass
that returns {class}`~.tornado.concurrent.Future` objects for use in {mod}`tornado` coroutines.
To use this API, import {class}`zmq.eventloop.future.Context`.
Sockets created by this Context will return Futures from any would-be blocking method.
```python
from tornado import gen, ioloop
import zmq
from zmq.eventloop.future import Context
ctx = Context.instance()
@gen.coroutine
def recv():
s = ctx.socket(zmq.SUB)
s.connect("tcp://127.0.0.1:5555")
s.subscribe(b"")
while True:
msg = yield s.recv_multipart()
print("received", msg)
s.close()
```
### {class}`ZMQStream`
{class}`ZMQStream` objects let you register callbacks to handle messages as they arrive,
for use with the tornado eventloop.
#### {meth}`send`
ZMQStream objects do have {meth}`~.ZMQStream.send` and {meth}`~.ZMQStream.send_multipart`
methods, which behaves the same way as {meth}`.Socket.send`, but instead of sending right
away, the {class}`.IOLoop` will wait until socket is able to send (for instance if `HWM`
is met, or a `REQ/REP` pattern prohibits sending at a certain point). Messages sent via
send will also be passed to the callback registered with {meth}`~.ZMQStream.on_send` after
sending.
#### {meth}`on_recv`
{meth}`.ZMQStream.on_recv` is the primary method for using a ZMQStream. It registers a
callback to fire with messages as they are received, which will *always* be multipart,
even if its length is 1. You can easily use this to build things like an echo socket:
```python
s = ctx.socket(zmq.REP)
s.bind("tcp://localhost:12345")
stream = ZMQStream(s)
def echo(msg):
stream.send_multipart(msg)
stream.on_recv(echo)
ioloop.IOLoop.instance().start()
```
on_recv can also take a `copy` flag, just like {meth}`.Socket.recv`. If `copy=False`, then
callbacks registered with on_recv will receive tracked {class}`.Frame` objects instead of
bytes.
```{note}
A callback must be registered using either {meth}`.ZMQStream.on_recv` or
{meth}`.ZMQStream.on_recv_stream` before any data will be received on the
underlying socket. This allows you to temporarily pause processing on a
socket by setting both callbacks to None. Processing can later be resumed
by restoring either callback.
```
#### {meth}`on_recv_stream`
{meth}`.ZMQStream.on_recv_stream` is just like on_recv above, but the callback will be
passed both the message and the stream, rather than just the message. This is meant to make
it easier to use a single callback with multiple streams.
```python
s1 = ctx.socket(zmq.REP)
s1.bind("tcp://localhost:12345")
stream1 = ZMQStream(s1)
s2 = ctx.socket(zmq.REP)
s2.bind("tcp://localhost:54321")
stream2 = ZMQStream(s2)
def echo(stream, msg):
stream.send_multipart(msg)
stream1.on_recv_stream(echo)
stream2.on_recv_stream(echo)
ioloop.IOLoop.instance().start()
```
#### {meth}`flush`
Sometimes with an eventloop, there can be multiple events ready on a single iteration of
the loop. The {meth}`~.ZMQStream.flush` method allows developers to pull messages off of
the queue to enforce some priority over the event loop ordering. flush pulls any pending
events off of the queue. You can specify to flush only recv events, only send events, or
any events, and you can specify a limit for how many events to flush in order to prevent
starvation.
### {func}`install()`
```{note}
If you are using pyzmq \< 17, there is an additional step
to tell tornado to use the zmq poller instead of its default.
{func}`.ioloop.install` is no longer needed for pyzmq ≥ 17.
```
With PyZMQ's ioloop, you can use zmq sockets in any tornado application. You can tell tornado to use zmq's poller by calling the {func}`.ioloop.install` function:
```python
from zmq.eventloop import ioloop
ioloop.install()
```
You can also do the same thing by requesting the global instance from pyzmq:
```python
from zmq.eventloop.ioloop import IOLoop
loop = IOLoop.current()
```
This configures tornado's {class}`tornado.ioloop.IOLoop` to use zmq's poller,
and registers the current instance.
Either `install()` or retrieving the zmq instance must be done before the global * instance is registered, else there will be a conflict.
It is possible to use PyZMQ sockets with tornado *without* registering as the global instance,
but it is less convenient. First, you must instruct the tornado IOLoop to use the zmq poller:
```python
from zmq.eventloop.ioloop import ZMQIOLoop
loop = ZMQIOLoop()
```
Then, when you instantiate tornado and ZMQStream objects, you must pass the `io_loop`
argument to ensure that they use this loop, instead of the global instance.
This is especially useful for writing tests, such as this:
```python
from tornado.testing import AsyncTestCase
from zmq.eventloop.ioloop import ZMQIOLoop
from zmq.eventloop.zmqstream import ZMQStream
class TestZMQBridge(AsyncTestCase):
# Use a ZMQ-compatible I/O loop so that we can use `ZMQStream`.
def get_new_ioloop(self):
return ZMQIOLoop()
```
You can also manually install this IOLoop as the global tornado instance, with:
```python
from zmq.eventloop.ioloop import ZMQIOLoop
loop = ZMQIOLoop()
loop.install()
```
(zmq-green)=
## PyZMQ and gevent
PyZMQ ≥ 2.2.0.1 ships with a [gevent](https://www.gevent.org/) compatible API as {mod}`zmq.green`.
To use it, simply:
```python
import zmq.green as zmq
```
Then write your code as normal.
Socket.send/recv and zmq.Poller are gevent-aware.
In PyZMQ ≥ 2.2.0.2, green.device and green.eventloop should be gevent-friendly as well.
```{note}
The green device does *not* release the GIL, unlike the true device in zmq.core.
```
zmq.green.eventloop includes minimally patched IOLoop/ZMQStream in order to use the gevent-enabled Poller,
so you should be able to use the ZMQStream interface in gevent apps as well,
though using two eventloops simultaneously (tornado + gevent) is not recommended.
```{warning}
There is a [known issue](https://github.com/zeromq/pyzmq/issues/229) in gevent ≤ 1.0 or libevent,
which can cause zeromq socket events to be missed.
PyZMQ works around this by adding a timeout so it will not wait forever for gevent to notice events.
The only known solution for this is to use gevent ≥ 1.0, which is currently at 1.0b3,
and does not exhibit this behavior.
```
```{seealso}
zmq.green examples [on GitHub](https://github.com/zeromq/pyzmq/tree/HEAD/examples/gevent).
```
{mod}`zmq.green` began as [gevent_zeromq](https://github.com/tmc/gevent-zeromq),
merged into the pyzmq project.
[tornado]: https://tornadoweb.org
# Using PyZMQ
```{toctree}
---
maxdepth: 2
---
morethanbindings.rst
serialization.rst
devices.rst
eventloop.rst
draft.rst
logging.rst
ssh.rst
```
% PyZMQ logging doc, by Min Ragan-Kelley, 2011
(logging)=
# Asynchronous Logging via PyZMQ
```{seealso}
- The ØMQ guide [coverage](https://zguide.zeromq.org/docs/chapter5/) of PUB/SUB
messaging
- Python logging module [documentation](https://docs.python.org/3/library/logging.html)
```
Python provides extensible logging facilities through its {py:mod}`logging` module. This
module allows for easily extensible logging functionality through the use of
{py:class}`~logging.Handler` objects. The most obvious case for hooking up pyzmq to
logging would be to broadcast log messages over a PUB socket, so we have provided a
{class}`.PUBHandler` class for doing just that.
You can use PyZMQ as a log handler with no previous knowledge of how ZMQ works,
and without writing any ZMQ-specific code in your Python project.
## Getting Started
Ensure you have installed the pyzmq package from pip, ideally in a
[virtual environment](https://docs.python.org/3/library/venv.html)
you created for your project:
```
pip install pyzmq
```
Next, configure logging in your Python module and setup the ZMQ log handler:
```
import logging
from zmq.log.handlers import PUBHandler
zmq_log_handler = PUBHandler('tcp://127.0.0.1:12345')
logger = logging.getLogger()
logger.addHandler(zmq_log_handler)
```
Usually, you will add the handler only once in the top-level module of your
project, on the root logger, just as we did here.
You can choose any IP address and port number that works on your system. We
used `tcp://127.0.0.1:12345` to broadcast events via TCP on the localhost
interface at port 12345. Make note of what you choose here as you will need it
later when you listen to the events.
Logging messages works exactly like normal. This will send an INFO-level
message on the logger we configured above, and that message will be
published on a ZMQ PUB/SUB socket:
```
logger.info('hello world!')
```
You can use this module's built-in command line interface to "tune in" to
messages broadcast by the log handler. To start the log watcher,
run this command from a shell that has access to the pyzmq package
(usually a virtual environment):
```
python -m zmq.log tcp://127.0.0.1:12345
```
Then, in a separate process, run your Python module that emits log
messages. You should see them appear almost immediately.
### Using the Log Watcher
The included log watcher command line utility is helpful not only for
viewing messages, but also a programming guide to build your own ZMQ
subscriber for log messages.
To see what options are available, pass the `--help` parameter:
```
python -m zmq.log --help
```
The log watcher includes features to add a timestamp to the messages,
align the messages across different error levels, and even colorize
the output based on error level.
### Slow Joiner Problem
The great thing about using ZMQ sockets is that you can start the publisher
and subscribers in any order, and you can start & stop any of them while
you leave the others running.
When using ZMQ for logging, this means you
can leave the log watcher running while you start & stop your main
Python module.
However, you need to be aware of what the ZMQ project calls the
["slow joiner problem"](https://zguide.zeromq.org/docs/chapter5/#Slow-Subscriber-Detection-Suicidal-Snail-Pattern) .
To oversimplify, it means it can take a bit of
time for subscribers to re-connect to a publisher that has just
started up again. If the publisher starts and immediately sends a
message, subscribers will likely miss it.
The simplistic workaround when using PyZMQ for logging is to `sleep()`
briefly after startup, before sending any log messages. See the complete
example below for more details.
### Custom Log Formats
A common Python logging recipe encourages
[use of the current module name](https://docs.python.org/3/howto/logging-cookbook.html#using-logging-in-multiple-modules)
as the name of the logger. This allows your log messages to reflect your
code hierarchy in a larger project with minimal configuration.
You will need to set a different formatter to see these names in your
ZMQ-published logs. The setFormatter() method accepts a logging.Formatter
instance and optionally a log level to apply the handler to. For example:
```
zmq_log_handler = PUBHandler('tcp://127.0.0.1:12345')
zmq_log_handler.setFormatter(logging.Formatter(fmt='{name} > {message}', style='{'))
zmq_log_handler.setFormatter(logging.Formatter(fmt='{name} #{lineno:>3} > {message}', style='{'), logging.DEBUG)
```
### Root Topic
By default, the PUBHandler and log watcher use the empty string as the
root topic for published messages. This works well out-of-the-box, but you can
easily set a different root topic string to take advantage of ZMQ's built-in
topic filtering mechanism.
First, set the root topic on the handler:
```python
zmq_log_handler = PUBHandler("<tcp://127.0.0.1:12345>")
zmq_log_handler.setRootTopic("custom_topic")
```
Then specify that topic when you start the log watcher:
```
python -m zmq.log -t custom_topic <tcp://127.0.0.1:12345>
```
### Complete example
Assuming this project hierarchy:
```
example.py
greetings.py
hello.py
```
If you have this in `example.py`:
```python
import logging
from time import sleep
from zmq.log.handlers import PUBHandler
from greetings import hello
zmq_log_handler = PUBHandler("tcp://127.0.0.1:12345")
zmq_log_handler.setFormatter(logging.Formatter(fmt="{name} > {message}", style="{"))
zmq_log_handler.setFormatter(
logging.Formatter(fmt="{name} #{lineno:>3} > {message}", style="{"), logging.DEBUG
)
zmq_log_handler.setRootTopic("greeter")
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logger.addHandler(zmq_log_handler)
if __name__ == "__main__":
sleep(0.1)
msg_count = 5
logger.warning("Preparing to greet the world...")
for i in range(1, msg_count + 1):
logger.debug("Sending message {} of {}".format(i, msg_count))
hello.world()
sleep(1.0)
logger.info("Done!")
```
And this in `hello.py`:
```
import logging
logger = logging.getLogger(__name__)
def world():
logger.info('hello world!')
```
You can start a log watcher in one process:
```
python -m zmq.log -t greeter --align tcp://127.0.0.1:12345
```
And then run `example.py` in another process:
```
python example.py
```
You should see the following output from the log watcher:
```
greeter.WARNING | root > Preparing to greet the world...
greeter.DEBUG | root # 21 > Sending message 1 of 5
greeter.INFO | greetings.hello > hello world!
greeter.DEBUG | root # 21 > Sending message 2 of 5
greeter.INFO | greetings.hello > hello world!
greeter.DEBUG | root # 21 > Sending message 3 of 5
greeter.INFO | greetings.hello > hello world!
greeter.DEBUG | root # 21 > Sending message 4 of 5
greeter.INFO | greetings.hello > hello world!
greeter.DEBUG | root # 21 > Sending message 5 of 5
greeter.INFO | greetings.hello > hello world!
greeter.INFO | root > Done!
```
## PUB/SUB and Topics
The ØMQ PUB/SUB pattern consists of a PUB socket broadcasting messages, and a collection
of SUB sockets that receive those messages. Each PUB message is a multipart-message, where
the first part is interpreted as a topic. SUB sockets can subscribe to topics by setting
their `SUBSCRIBE` sockopt, e.g.:
```
sub = ctx.socket(zmq.SUB)
sub.setsockopt(zmq.SUBSCRIBE, 'topic1')
sub.setsockopt(zmq.SUBSCRIBE, 'topic2')
```
When subscribed, the SUB socket will only receive messages where the first part *starts
with* one of the topics set via `SUBSCRIBE`. The default behavior is to exclude all
messages, and subscribing to the empty string '' will receive all messages.
## PUBHandler
The {class}`.PUBHandler` object is created for allowing the python logging to be emitted
on a PUB socket. The main difference between a PUBHandler and a regular logging Handler is
the inclusion of topics. For the most basic logging, you can simply create a PUBHandler
with an interface or a configured PUB socket, and just let it go:
```
pub = context.socket(zmq.PUB)
pub.bind('tcp://*:12345')
handler = PUBHandler(pub)
logger = logging.getLogger()
logger.addHandler(handler)
```
At this point, all messages logged with the default logger will be broadcast on the pub
socket.
the PUBHandler does work with topics, and the handler has an attribute `root_topic`:
```python
handler.root_topic = "myprogram"
```
Python loggers also have loglevels. The base topic of messages emitted by the PUBHandler
will be of the form: `<handler.root_topic>.<loglevel>`, e.g. 'myprogram.INFO' or
'whatever.ERROR'. This way, subscribers can easily subscribe to subsets of the logging
messages. Log messages are always two-part, where the first part is the topic tree, and
the second part is the actual log message.
```python
logger.info("hello there")
print(sub.recv_multipart())
```
```
[b"myprogram.INFO", b"hello there"]
```
### Subtopics
You can also add to the topic tree below the loglevel on an individual message basis.
Assuming your logger is connected to a PUBHandler, you can add as many additional topics
on the front of the message, which will be added always after the loglevel. A special
delimiter defined at `zmq.log.handlers.TOPIC_DELIM` is scanned by the PUBHandler, so if
you pass your own subtopics prior to that symbol, they will be stripped from the message
and added to the topic tree:
```
>>> log_msg = "hello there"
>>> subtopic = "sub.topic"
>>> msg = zmq.log.handlers.TOPIC_DELIM.join([subtopic, log_msg])
>>> logger.warn(msg)
>>> print sub.recv_multipart()
['myprogram.WARN.sub.topic', 'hello there']
```
% PyZMQ Bindings doc, by Min Ragan-Kelley, 2011
(bindings)=
# More Than Just Bindings
PyZMQ is ostensibly the Python bindings for [ØMQ], but the project, following
Python's 'batteries included' philosophy, provides more than just Python methods and
objects for calling into the ØMQ C++ library.
## The Core as Bindings
PyZMQ is currently broken up into four subpackages. First, is the Core. {mod}`zmq.core`
contains the actual bindings for ZeroMQ, and no extended functionality beyond the very
basic. The core modules are split, such that each basic ZeroMQ object (or function, if no
object is associated) is a separate module, e.g. {mod}`zmq.core.context` contains the
{class}`.Context` object, {mod}`zmq.core.poll` contains a {class}`.Poller` object, as well
as the {func}`.select` function, etc. ZMQ constants are, for convenience, all kept
together in {mod}`zmq.core.constants`.
There are two reasons for breaking the core into submodules: *recompilation* and
*derivative projects*. The monolithic PyZMQ became quite tedious to have to recompile
everything for a small change to a single object. With separate files, that's no longer
necessary. The second reason has to do with Cython. PyZMQ is written in Cython, a tool for
efficiently writing C-extensions for Python. By separating out our objects into individual
`pyx` files, each with their declarations in a `pxd` header, other projects can write
extensions in Cython and call directly to ZeroMQ at the C-level without the penalty of
going through our Python objects.
## Thread Safety
In ØMQ, Contexts are threadsafe objects, but Sockets are **not**. It is safe to use a
single Context (e.g. via {meth}`zmq.Context.instance`) in your entire multithreaded
application, but you should create sockets on a per-thread basis. If you share sockets
across threads, you are likely to encounter uncatchable c-level crashes of your
application unless you use judicious application of {py:class}`threading.Lock`, but this
approach is not recommended.
```{seealso}
ZeroMQ API note on threadsafety on [2.2](http://api.zeromq.org/2-2:zmq)
or [3.2](http://api.zeromq.org/3-2:zmq)
```
## Socket Options as Attributes
```{versionadded} 2.1.9
```
In 0MQ, socket options are set/retrieved with the {meth}`set/getsockopt` methods. With the
class-based approach in pyzmq, it would be logical to perform these operations with
simple attribute access, and this has been added in pyzmq 2.1.9. Simply assign to or
request a Socket attribute with the (case-insensitive) name of a sockopt, and it should
behave just as you would expect:
```python
s = ctx.socket(zmq.DEALER)
s.identity = b"dealer"
s.hwm = 10
s.events
# 0
s.fd
# 16
```
### Default Options on the Context
```{versionadded} 2.1.11
```
Just like setting socket options as attributes on Sockets, you can do the same on Contexts.
This affects the default options of any *new* sockets created after the assignment.
```python
ctx = zmq.Context()
ctx.linger = 0
rep = ctx.socket(zmq.REP)
req = ctx.socket(zmq.REQ)
```
Socket options that do not apply to a socket (e.g. SUBSCRIBE on non-SUB sockets) will
simply be ignored.
## libzmq constants as Enums
```{versionadded} 23
```
libzmq constants are now available as Python enums,
making it easier to enumerate socket options, etc.
## Context managers
```{versionadded} 14
Context/Sockets as context managers
```
```{versionadded} 20
bind/connect context managers
```
For more Pythonic resource management,
contexts and sockets can be used as context managers.
Just like standard-library socket and file methods,
entering a context:
```python
import zmq
with zmq.Context() as ctx:
with ctx.socket(zmq.PUSH) as s:
s.connect(url)
s.send_multipart([b"message"])
# exiting Socket context closes socket
# exiting Context context terminates context
```
In addition, each bind/connect call may be used as a context:
```python
with socket.connect(url):
s.send_multipart([b"message"])
# exiting connect context calls socket.disconnect(url)
```
## Core Extensions
We have extended the core functionality in two ways that appear inside the {mod}`core`
bindings, and are not general ØMQ features.
### Builtin Serialization
First, we added common serialization with the builtin {py:mod}`json` and {py:mod}`pickle`
as first-class methods to the {class}`Socket` class. A socket has the methods
{meth}`~.Socket.send_json` and {meth}`~.Socket.send_pyobj`, which correspond to sending an
object over the wire after serializing with {mod}`json` and {mod}`pickle` respectively,
and any object sent via those methods can be reconstructed with the
{meth}`~.Socket.recv_json` and {meth}`~.Socket.recv_pyobj` methods. Unicode strings are
other objects that are not unambiguously sendable over the wire, so we include
{meth}`~.Socket.send_string` and {meth}`~.Socket.recv_string` that simply send bytes
after encoding the message ('utf-8' is the default).
```{seealso}
- {ref}`Further information <serialization>` on serialization in pyzmq.
- {ref}`Our Unicode discussion <unicode>` for more information on the trials and
tribulations of working with Unicode in a C extension while supporting Python 2 and 3.
```
### MessageTracker
The second extension of basic ØMQ functionality is the {class}`MessageTracker`. The
MessageTracker is an object used to track when the underlying ZeroMQ is done with a
message buffer. One of the main use cases for ØMQ in Python is the ability to perform
non-copying sends. Thanks to Python's buffer interface, many objects (including NumPy
arrays) provide the buffer interface, and are thus directly sendable. However, as with any
asynchronous non-copying messaging system like ØMQ or MPI, it can be important to know
when the message has actually been sent, so it is safe again to edit the buffer without
worry of corrupting the message. This is what the MessageTracker is for.
The MessageTracker is a simple object, but there is a penalty to its use. Since by its
very nature, the MessageTracker must involve threadsafe communication (specifically a
builtin {py:class}`~Queue.Queue` object), instantiating a MessageTracker takes a modest
amount of time (10s of µs), so in situations instantiating many small messages, this can
actually dominate performance. As a result, tracking is optional, via the `track` flag,
which is optionally passed, always defaulting to `False`, in each of the three places
where a Frame object (the pyzmq object for wrapping a segment of a message) is
instantiated: The {class}`.Frame` constructor, and non-copying sends and receives.
A MessageTracker is very simple, and has just one method and one attribute. The property
{attr}`MessageTracker.done` will be `True` when the Frame(s) being tracked are no
longer in use by ØMQ, and {meth}`.MessageTracker.wait` will block, waiting for the
Frame(s) to be released.
```{Note}
A Frame cannot be tracked after it has been instantiated without tracking. If a
Frame is to even have the *option* of tracking, it must be constructed with
`track=True`.
```
## Extensions
So far, PyZMQ includes four extensions to core ØMQ that we found basic enough to be
included in PyZMQ itself:
- {ref}`zmq.log <logging>` : Logging handlers for hooking Python logging up to the
network
- {ref}`zmq.devices <devices>` : Custom devices and objects for running devices in the
background
- {ref}`zmq.eventloop <eventloop>` : The [Tornado] event loop, adapted for use
with ØMQ sockets.
- {ref}`zmq.ssh <ssh>` : Simple tools for tunneling zeromq connections via ssh.
[tornado]: https://www.tornadoweb.org
[ømq]: https://zeromq.org/
This source diff could not be displayed because it is too large. You can view the blob instead.
This image diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment