File: zmq.eventloop.future.md

package info (click to toggle)
pyzmq 27.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,984 kB
  • sloc: python: 15,189; ansic: 285; makefile: 169; sh: 85
file content (93 lines) | stat: -rw-r--r-- 1,807 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
% AUTO-GENERATED FILE -- DO NOT EDIT!

# eventloop.future

## Module: {mod}`zmq.eventloop.future`

```{eval-rst}
.. 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}`Socket`.
You can create these sockets by instantiating a {class}`Context`
from the same module.
These sockets let you easily use zmq with tornado's coroutines.

```{seealso}
{mod}`tornado.gen`
```

```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.

```{eval-rst}
.. autoclass:: Context

```

### {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.
```

```{eval-rst}
.. autoclass:: Socket

  .. 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.
```

```{eval-rst}
.. autoclass:: Poller

  .. automethod:: poll
      :noindex:
```