/usr/share/doc/pyzo-doc/html/yoton/channels.html is in pyzo-doc 4.3.1-1+deb9u1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Channels — Pyzo 3.4 documentation</title>
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '3.4',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="top" title="Pyzo 3.4 documentation" href="../index.html" />
<link rel="up" title="Yoton - Inter process communication" href="index.html" />
<link rel="next" title="Event system" href="events.html" />
<link rel="prev" title="Connection" href="connection.html" />
</head>
<body role="document">
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="events.html" title="Event system"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="connection.html" title="Connection"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Pyzo 3.4 documentation</a> »</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Yoton - Inter process communication</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="channels">
<h1>Channels<a class="headerlink" href="#channels" title="Permalink to this headline">¶</a></h1>
<p>The channel classes represent the mechanism for the user to send
messages into the network and receive messages from it. A channel
needs a context to function; the context represents a node in the
network.</p>
<div class="section" id="slots">
<h2>Slots<a class="headerlink" href="#slots" title="Permalink to this headline">¶</a></h2>
<p>To be able to route messages to the right channel, channels are
associated with a slot (a string name). This slot consists of a
user-defined base name and an extension to tell the message type
and messaging pattern. Messages send from a channel with slot X,
are only received by channels with the same slot X. Slots are case
insensitive.</p>
</div>
<div class="section" id="messaging-patterns">
<h2>Messaging patterns<a class="headerlink" href="#messaging-patterns" title="Permalink to this headline">¶</a></h2>
<p>Yoton supports three base messaging patterns. For each messaging pattern
there are specific channel classes. All channels derive from <a class="reference internal" href="#insertdocs-yoton-basechannel"><span class="std std-ref">yoton.BaseChannel</span></a>.</p>
<p><strong>publish/subscribe</strong>
The <a class="reference internal" href="#insertdocs-yoton-pubchannel"><span class="std std-ref">yoton.PubChannel</span></a> class is used for sending messages into the network, and
the <a class="reference internal" href="#insertdocs-yoton-subchannel"><span class="std std-ref">yoton.SubChannel</span></a> class is used to receiving these messages. Multiple
PubChannels and SubChannels can exist in the same network at the same
slot; the SubChannels simply collect the messages send by all PubChannels.</p>
<p><strong>request/reply</strong>
The <a class="reference internal" href="#insertdocs-yoton-reqchannel"><span class="std std-ref">yoton.ReqChannel</span></a> class is used to do requests, and the <a class="reference internal" href="#insertdocs-yoton-repchannel"><span class="std std-ref">yoton.RepChannel</span></a>
class is
used to reply to requests. If multiple ReqChannels are present at the
same slot, simple load balancing is performed.</p>
<p><strong>state</strong>
The <a class="reference internal" href="#insertdocs-yoton-statechannel"><span class="std std-ref">yoton.StateChannel</span></a> class is used to communicate state to other state
channels. Each <a class="reference internal" href="#insertdocs-yoton-statechannel"><span class="std std-ref">yoton.StateChannel</span></a> can set and get the state.</p>
</div>
<div class="section" id="message-types">
<h2>Message types<a class="headerlink" href="#message-types" title="Permalink to this headline">¶</a></h2>
<p>Messages are of a specific type (text, binary, ...), the default being
Unicode text. The third (optional) argument to a Channel’s initializer
is a MessageType object that specifies how messages should be converted
to bytes and the other way around.</p>
<p>This way, the channels classes themself can be agnostic about the message
type, while the user can implement its own MessageType class to send
whatever messages he/she likes.</p>
<span class="target" id="insertdocs-yoton-basechannel"></span><dl class="class">
<dt id="yoton.BaseChannel">
<em class="property">class </em><code class="descclassname">yoton.</code><code class="descname">BaseChannel</code><span class="sig-paren">(</span><em>context</em>, <em>slot_base</em>, <em>message_type=yoton.TEXT</em><span class="sig-paren">)</span><a class="headerlink" href="#yoton.BaseChannel" title="Permalink to this definition">¶</a></dt>
<dd><p><em>Inherits from object</em></p>
<p>Abstract class for all channels.</p>
<p><strong>Parameters</strong></p>
<dl class="docutils">
<dt>context</dt>
<span class="classifier-delimiter">:</span> <span class="classifier"><a class="reference internal" href="context.html#insertdocs-yoton-context"><span class="std std-ref">yoton.Context</span></a> instance</span><dd>The context that this channel uses to send messages in a network.</dd>
<dt>slot_base</dt>
<span class="classifier-delimiter">:</span> <span class="classifier">string</span><dd>The base slot name. The channel appends an extension to indicate
message type and messaging pattern to create the final slot name.
The final slot is used to connect channels at different contexts
in a network</dd>
<dt>message_type</dt>
<span class="classifier-delimiter">:</span> <span class="classifier">yoton.MessageType instance</span><dd>(default is yoton.TEXT)
Object to convert messages to bytes and bytes to messages.
Users can create their own message_type class to enable
communicating any type of message they want.</dd>
</dl>
<p><strong>Details</strong></p>
<p>Messages send via a channel are delivered asynchronically to the
corresponding channels.</p>
<p>All channels are associated with a context and can be used to send
messages to other channels in the network. Each channel is also
associated with a slot, which is a string that represents a kind
of address. A message send by a channel at slot X can only be received
by a channel with slot X.</p>
<p>Note that the channel appends an extension
to the user-supplied slot name, that represents the message type
and messaging pattern of the channel. In this way, it is prevented
that for example a PubChannel can communicate with a RepChannel.</p>
<p><em>PROPERTIES</em></p>
<span class="target" id="insertdocs-yoton-basechannel-closed"></span><dl class="attribute">
<dt id="yoton.BaseChannel.closed">
<code class="descname">closed</code><a class="headerlink" href="#yoton.BaseChannel.closed" title="Permalink to this definition">¶</a></dt>
<dd><p>Get whether the channel is closed.</p>
</dd></dl>
<span class="target" id="insertdocs-yoton-basechannel-pending"></span><dl class="attribute">
<dt id="yoton.BaseChannel.pending">
<code class="descname">pending</code><a class="headerlink" href="#yoton.BaseChannel.pending" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the number of pending incoming messages.</p>
</dd></dl>
<span class="target" id="insertdocs-yoton-basechannel-received"></span><dl class="attribute">
<dt id="yoton.BaseChannel.received">
<code class="descname">received</code><a class="headerlink" href="#yoton.BaseChannel.received" title="Permalink to this definition">¶</a></dt>
<dd><p>Signal that is emitted when new data is received. Multiple
arrived messages may result in a single call to this method.
There is no guarantee that recv() has not been called in the
mean time. The signal is emitted with the channel instance
as argument.</p>
</dd></dl>
<span class="target" id="insertdocs-yoton-basechannel-slot-incoming"></span><dl class="attribute">
<dt id="yoton.BaseChannel.slot_incoming">
<code class="descname">slot_incoming</code><a class="headerlink" href="#yoton.BaseChannel.slot_incoming" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the incoming slot name.</p>
</dd></dl>
<span class="target" id="insertdocs-yoton-basechannel-slot-outgoing"></span><dl class="attribute">
<dt id="yoton.BaseChannel.slot_outgoing">
<code class="descname">slot_outgoing</code><a class="headerlink" href="#yoton.BaseChannel.slot_outgoing" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the outgoing slot name.</p>
</dd></dl>
<p><em>METHODS</em></p>
<span class="target" id="insertdocs-yoton-basechannel-close"></span><dl class="method">
<dt id="yoton.BaseChannel.close">
<code class="descname">close</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#yoton.BaseChannel.close" title="Permalink to this definition">¶</a></dt>
<dd><p>Close the channel, i.e. unregisters this channel at the context.
A closed channel cannot be reused.</p>
<p>Future attempt to send() messages will result in an IOError
being raised. Messages currently in the channel’s queue can
still be recv()’ed, but no new messages will be delivered at
this channel.</p>
</dd></dl>
</dd></dl>
<span class="target" id="insertdocs-yoton-pubchannel"></span><dl class="class">
<dt id="yoton.PubChannel">
<em class="property">class </em><code class="descclassname">yoton.</code><code class="descname">PubChannel</code><span class="sig-paren">(</span><em>context</em>, <em>slot_base</em>, <em>message_type=yoton.TEXT</em><span class="sig-paren">)</span><a class="headerlink" href="#yoton.PubChannel" title="Permalink to this definition">¶</a></dt>
<dd><p><em>Inherits from BaseChannel</em></p>
<p>The publish part of the publish/subscribe messaging pattern.
Sent messages are received by all <a class="reference internal" href="#insertdocs-yoton-subchannel"><span class="std std-ref">yoton.SubChannel</span></a> instances with
the same slot.</p>
<p>There are no limitations for this channel if events are not processed.</p>
<p><strong>Parameters</strong></p>
<dl class="docutils">
<dt>context</dt>
<span class="classifier-delimiter">:</span> <span class="classifier"><a class="reference internal" href="context.html#insertdocs-yoton-context"><span class="std std-ref">yoton.Context</span></a> instance</span><dd>The context that this channel uses to send messages in a network.</dd>
<dt>slot_base</dt>
<span class="classifier-delimiter">:</span> <span class="classifier">string</span><dd>The base slot name. The channel appends an extension to indicate
message type and messaging pattern to create the final slot name.
The final slot is used to connect channels at different contexts
in a network</dd>
<dt>message_type</dt>
<span class="classifier-delimiter">:</span> <span class="classifier">yoton.MessageType instance</span><dd>(default is yoton.TEXT)
Object to convert messages to bytes and bytes to messages.
Users can create their own message_type class to let channels
any type of message they want.</dd>
</dl>
<p><em>METHODS</em></p>
<span class="target" id="insertdocs-yoton-pubchannel-send"></span><dl class="method">
<dt id="yoton.PubChannel.send">
<code class="descname">send</code><span class="sig-paren">(</span><em>message</em><span class="sig-paren">)</span><a class="headerlink" href="#yoton.PubChannel.send" title="Permalink to this definition">¶</a></dt>
<dd><p>Send a message over the channel. What is send as one
message will also be received as one message.</p>
<p>The message is queued and delivered to all corresponding
SubChannels (i.e. with the same slot) in the network.</p>
</dd></dl>
</dd></dl>
<span class="target" id="insertdocs-yoton-subchannel"></span><dl class="class">
<dt id="yoton.SubChannel">
<em class="property">class </em><code class="descclassname">yoton.</code><code class="descname">SubChannel</code><span class="sig-paren">(</span><em>context</em>, <em>slot_base</em>, <em>message_type=yoton.TEXT</em><span class="sig-paren">)</span><a class="headerlink" href="#yoton.SubChannel" title="Permalink to this definition">¶</a></dt>
<dd><p><em>Inherits from BaseChannel</em></p>
<p>The subscribe part of the publish/subscribe messaging pattern.
Received messages were sent by a <a class="reference internal" href="#insertdocs-yoton-pubchannel"><span class="std std-ref">yoton.PubChannel</span></a> instance at the
same slot.</p>
<p>This channel can be used as an iterator, which yields all pending
messages. The function <a class="reference internal" href="#insertdocs-yoton-select-sub-channel"><span class="std std-ref">yoton.select_sub_channel</span></a> can
be used to synchronize multiple SubChannel instances.</p>
<p>If no events being processed this channel works as normal, except
that the received signal will not be emitted, and sync mode will
not work.</p>
<p><strong>Parameters</strong></p>
<dl class="docutils">
<dt>context</dt>
<span class="classifier-delimiter">:</span> <span class="classifier"><a class="reference internal" href="context.html#insertdocs-yoton-context"><span class="std std-ref">yoton.Context</span></a> instance</span><dd>The context that this channel uses to send messages in a network.</dd>
<dt>slot_base</dt>
<span class="classifier-delimiter">:</span> <span class="classifier">string</span><dd>The base slot name. The channel appends an extension to indicate
message type and messaging pattern to create the final slot name.
The final slot is used to connect channels at different contexts
in a network</dd>
<dt>message_type</dt>
<span class="classifier-delimiter">:</span> <span class="classifier">yoton.MessageType instance</span><dd>(default is yoton.TEXT)
Object to convert messages to bytes and bytes to messages.
Users can create their own message_type class to let channels
any type of message they want.</dd>
</dl>
<p><em>METHODS</em></p>
<span class="target" id="insertdocs-yoton-subchannel-next"></span><dl class="method">
<dt id="yoton.SubChannel.next">
<code class="descname">next</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#yoton.SubChannel.next" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the next message, or raises StopIteration if non available.</p>
</dd></dl>
<span class="target" id="insertdocs-yoton-subchannel-recv"></span><dl class="method">
<dt id="yoton.SubChannel.recv">
<code class="descname">recv</code><span class="sig-paren">(</span><em>block=True</em><span class="sig-paren">)</span><a class="headerlink" href="#yoton.SubChannel.recv" title="Permalink to this definition">¶</a></dt>
<dd><p>Receive a message from the channel. What was send as one
message is also received as one message.</p>
<p>If block is False, returns empty message if no data is available.
If block is True, waits forever until data is available.
If block is an int or float, waits that many seconds.
If the channel is closed, returns empty message.</p>
</dd></dl>
<span class="target" id="insertdocs-yoton-subchannel-recv-all"></span><dl class="method">
<dt id="yoton.SubChannel.recv_all">
<code class="descname">recv_all</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#yoton.SubChannel.recv_all" title="Permalink to this definition">¶</a></dt>
<dd><p>Receive a list of all pending messages. The list can be empty.</p>
</dd></dl>
<span class="target" id="insertdocs-yoton-subchannel-recv-selected"></span><dl class="method">
<dt id="yoton.SubChannel.recv_selected">
<code class="descname">recv_selected</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#yoton.SubChannel.recv_selected" title="Permalink to this definition">¶</a></dt>
<dd><p>Receive a list of messages. Use only after calling
<a class="reference internal" href="#insertdocs-yoton-select-sub-channel"><span class="std std-ref">yoton.select_sub_channel</span></a> with this channel as one of the arguments.</p>
<p>The returned messages are all received before the first pending
message in the other SUB-channels given to select_sub_channel.</p>
<p>The combination of this method and the function select_sub_channel
enables users to combine multiple SUB-channels in a way that
preserves the original order of the messages.</p>
</dd></dl>
<span class="target" id="insertdocs-yoton-subchannel-set-sync-mode"></span><dl class="method">
<dt id="yoton.SubChannel.set_sync_mode">
<code class="descname">set_sync_mode</code><span class="sig-paren">(</span><em>value</em><span class="sig-paren">)</span><a class="headerlink" href="#yoton.SubChannel.set_sync_mode" title="Permalink to this definition">¶</a></dt>
<dd><p>Set or unset the SubChannel in sync mode. When in sync mode, all
channels that send messages to this channel are blocked if
the queue for this SubChannel reaches a certain size.</p>
<p>This feature can be used to limit the rate of senders if the consumer
(i.e. the one that calls recv()) cannot keep up with processing
the data.</p>
<p>This feature requires the yoton event loop to run at the side
of the SubChannel (not necessary for the <a class="reference internal" href="#insertdocs-yoton-pubchannel"><span class="std std-ref">yoton.PubChannel</span></a> side).</p>
</dd></dl>
</dd></dl>
<span class="target" id="insertdocs-yoton-select-sub-channel"></span><dl class="function">
<dt id="yoton.select_sub_channel">
<code class="descclassname">yoton.</code><code class="descname">select_sub_channel</code><span class="sig-paren">(</span><em>channel1</em>, <em>channel2</em>, <em>...</em><span class="sig-paren">)</span><a class="headerlink" href="#yoton.select_sub_channel" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the channel that has the oldest pending message of all
given yoton.SubCannel instances. Returns None if there are no pending
messages.</p>
<p>This function can be used to read from SubCannels instances in the
order that the messages were send.</p>
<p>After calling this function, use channel.recv_selected() to obtain
all messages that are older than any pending messages in the other
given channels.</p>
</dd></dl>
<span class="target" id="insertdocs-yoton-reqchannel"></span><dl class="class">
<dt id="yoton.ReqChannel">
<em class="property">class </em><code class="descclassname">yoton.</code><code class="descname">ReqChannel</code><span class="sig-paren">(</span><em>context</em>, <em>slot_base</em><span class="sig-paren">)</span><a class="headerlink" href="#yoton.ReqChannel" title="Permalink to this definition">¶</a></dt>
<dd><p><em>Inherits from BaseChannel</em></p>
<p>The request part of the request/reply messaging pattern.
A ReqChannel instance sends request and receive the corresponding
replies. The requests are replied by a <a class="reference internal" href="#insertdocs-yoton-repchannel"><span class="std std-ref">yoton.RepChannel</span></a> instance.</p>
<p>This class adopts req/rep in a remote procedure call (RPC) scheme.
The handling of the result is done using a <a class="reference internal" href="#insertdocs-yoton-future"><span class="std std-ref">yoton.Future</span></a> object, which
follows the approach specified in PEP 3148. Note that for the use
of callbacks, the yoton event loop must run.</p>
<p>Basic load balancing is performed by first asking all potential
repliers whether they can handle a request. The actual request
is then send to the first replier to respond.</p>
<p><strong>Parameters</strong></p>
<dl class="docutils">
<dt>context</dt>
<span class="classifier-delimiter">:</span> <span class="classifier"><a class="reference internal" href="context.html#insertdocs-yoton-context"><span class="std std-ref">yoton.Context</span></a> instance</span><dd>The context that this channel uses to send messages in a network.</dd>
<dt>slot_base</dt>
<span class="classifier-delimiter">:</span> <span class="classifier">string</span><dd>The base slot name. The channel appends an extension to indicate
message type and messaging pattern to create the final slot name.
The final slot is used to connect channels at different contexts
in a network</dd>
</dl>
<p><strong>Usage</strong></p>
<p>One performs a call on a virtual method of this object. The actual
method is executed by the <a class="reference internal" href="#insertdocs-yoton-repchannel"><span class="std std-ref">yoton.RepChannel</span></a> instance. The method can be
called with normal and keyword arguments, which can be (a
combination of): None, bool, int, float, string, list, tuple, dict.</p>
<p><strong>Example</strong></p>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="c1"># Fast, but process is idling when waiting for the response.</span>
<span class="n">reply</span> <span class="o">=</span> <span class="n">req</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">)</span><span class="o">.</span><span class="n">result</span><span class="p">(</span><span class="mf">2.0</span><span class="p">)</span> <span class="c1"># Wait two seconds</span>
<span class="c1"># Asynchronous processing, but no waiting.</span>
<span class="k">def</span> <span class="nf">reply_handler</span><span class="p">(</span><span class="n">future</span><span class="p">):</span>
<span class="o">...</span> <span class="c1"># Handle reply</span>
<span class="n">future</span> <span class="o">=</span> <span class="n">req</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span><span class="mi">4</span><span class="p">)</span>
<span class="n">future</span><span class="o">.</span><span class="n">add_done_callback</span><span class="p">(</span><span class="n">reply_handler</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>
<span class="target" id="insertdocs-yoton-repchannel"></span><dl class="class">
<dt id="yoton.RepChannel">
<em class="property">class </em><code class="descclassname">yoton.</code><code class="descname">RepChannel</code><span class="sig-paren">(</span><em>context</em>, <em>slot_base</em><span class="sig-paren">)</span><a class="headerlink" href="#yoton.RepChannel" title="Permalink to this definition">¶</a></dt>
<dd><p><em>Inherits from BaseChannel</em></p>
<p>The reply part of the request/reply messaging pattern.
A RepChannel instance receives request and sends the corresponding
replies. The requests are send from a <a class="reference internal" href="#insertdocs-yoton-reqchannel"><span class="std std-ref">yoton.ReqChannel</span></a> instance.</p>
<p>This class adopts req/rep in a remote procedure call (RPC) scheme.</p>
<p>To use a RepChannel, subclass this class and implement the methods
that need to be available. The reply should be (a combination of)
None, bool, int, float, string, list, tuple, dict.</p>
<p>This channel needs to be set to event or thread mode to function
(in the first case yoton events need to be processed too).
To stop handling events again, use set_mode(‘off’).</p>
<p><strong>Parameters</strong></p>
<dl class="docutils">
<dt>context</dt>
<span class="classifier-delimiter">:</span> <span class="classifier"><a class="reference internal" href="context.html#insertdocs-yoton-context"><span class="std std-ref">yoton.Context</span></a> instance</span><dd>The context that this channel uses to send messages in a network.</dd>
<dt>slot_base</dt>
<span class="classifier-delimiter">:</span> <span class="classifier">string</span><dd>The base slot name. The channel appends an extension to indicate
message type and messaging pattern to create the final slot name.
The final slot is used to connect channels at different contexts
in a network</dd>
</dl>
<p><em>METHODS</em></p>
<span class="target" id="insertdocs-yoton-repchannel-echo"></span><dl class="method">
<dt id="yoton.RepChannel.echo">
<code class="descname">echo</code><span class="sig-paren">(</span><em>arg1</em>, <em>sleep=0.0</em><span class="sig-paren">)</span><a class="headerlink" href="#yoton.RepChannel.echo" title="Permalink to this definition">¶</a></dt>
<dd><p>Default procedure that can be used for testing. It returns
a tuple (first_arg, context_id)</p>
</dd></dl>
<span class="target" id="insertdocs-yoton-repchannel-set-mode"></span><dl class="method">
<dt id="yoton.RepChannel.set_mode">
<code class="descname">set_mode</code><span class="sig-paren">(</span><em>mode</em><span class="sig-paren">)</span><a class="headerlink" href="#yoton.RepChannel.set_mode" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the replier to its operating mode, or turn it off.</p>
<dl class="docutils">
<dt>Modes:</dt>
<dd><ul class="first last simple">
<li>0 or ‘off’: do not process requests</li>
<li>1 or ‘event’: use the yoton event loop to process requests</li>
<li>2 or ‘thread’: process requests in a separate thread</li>
</ul>
</dd>
</dl>
</dd></dl>
</dd></dl>
<span class="target" id="insertdocs-yoton-future"></span><dl class="class">
<dt id="yoton.Future">
<em class="property">class </em><code class="descclassname">yoton.</code><code class="descname">Future</code><span class="sig-paren">(</span><em>req_channel</em>, <em>req</em>, <em>request_id</em><span class="sig-paren">)</span><a class="headerlink" href="#yoton.Future" title="Permalink to this definition">¶</a></dt>
<dd><p><em>Inherits from object</em></p>
<p>The Future object represents the future result of a request done at
a <a class="reference internal" href="#insertdocs-yoton-reqchannel"><span class="std std-ref">yoton.ReqChannel</span></a>.</p>
<dl class="docutils">
<dt>It enables:</dt>
<dd><ul class="first last simple">
<li>checking whether the request is done.</li>
<li>getting the result or the exception raised during handling the request.</li>
<li>canceling the request (if it is not yet running)</li>
<li>registering callbacks to handle the result when it is available</li>
</ul>
</dd>
</dl>
<p><em>METHODS</em></p>
<span class="target" id="insertdocs-yoton-future-add-done-callback"></span><dl class="method">
<dt id="yoton.Future.add_done_callback">
<code class="descname">add_done_callback</code><span class="sig-paren">(</span><em>fn</em><span class="sig-paren">)</span><a class="headerlink" href="#yoton.Future.add_done_callback" title="Permalink to this definition">¶</a></dt>
<dd><p>Attaches the callable fn to the future. fn will be called, with
the future as its only argument, when the future is cancelled or
finishes running.</p>
<p>Added callables are called in the order that they were added. If
the callable raises a Exception subclass, it will be logged and
ignored. If the callable raises a BaseException subclass, the
behavior is undefined.</p>
<p>If the future has already completed or been cancelled, fn will be
called immediately.</p>
</dd></dl>
<span class="target" id="insertdocs-yoton-future-cancel"></span><dl class="method">
<dt id="yoton.Future.cancel">
<code class="descname">cancel</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#yoton.Future.cancel" title="Permalink to this definition">¶</a></dt>
<dd><p>Attempt to cancel the call. If the call is currently being executed
and cannot be cancelled then the method will return False, otherwise
the call will be cancelled and the method will return True.</p>
</dd></dl>
<span class="target" id="insertdocs-yoton-future-cancelled"></span><dl class="method">
<dt id="yoton.Future.cancelled">
<code class="descname">cancelled</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#yoton.Future.cancelled" title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if the call was successfully cancelled.</p>
</dd></dl>
<span class="target" id="insertdocs-yoton-future-done"></span><dl class="method">
<dt id="yoton.Future.done">
<code class="descname">done</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#yoton.Future.done" title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if the call was successfully cancelled or finished running.</p>
</dd></dl>
<span class="target" id="insertdocs-yoton-future-exception"></span><dl class="method">
<dt id="yoton.Future.exception">
<code class="descname">exception</code><span class="sig-paren">(</span><em>timeout</em><span class="sig-paren">)</span><a class="headerlink" href="#yoton.Future.exception" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the exception raised by the call. If the call hasn’t yet
completed then this method will wait up to timeout seconds. If
the call hasn’t completed in timeout seconds, then a TimeoutError
will be raised. timeout can be an int or float. If timeout is not
specified or None, there is no limit to the wait time.</p>
<p>If the future is cancelled before completing then CancelledError
will be raised.</p>
<p>If the call completed without raising, None is returned.</p>
</dd></dl>
<span class="target" id="insertdocs-yoton-future-result"></span><dl class="method">
<dt id="yoton.Future.result">
<code class="descname">result</code><span class="sig-paren">(</span><em>timeout=None</em><span class="sig-paren">)</span><a class="headerlink" href="#yoton.Future.result" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the value returned by the call. If the call hasn’t yet
completed then this method will wait up to timeout seconds. If
the call hasn’t completed in timeout seconds, then a TimeoutError
will be raised. timeout can be an int or float. If timeout is not
specified or None, there is no limit to the wait time.</p>
<p>If the future is cancelled before completing then CancelledError
will be raised.</p>
<p>If the call raised, this method will raise the same exception.</p>
</dd></dl>
<span class="target" id="insertdocs-yoton-future-result-or-cancel"></span><dl class="method">
<dt id="yoton.Future.result_or_cancel">
<code class="descname">result_or_cancel</code><span class="sig-paren">(</span><em>timeout=1.0</em><span class="sig-paren">)</span><a class="headerlink" href="#yoton.Future.result_or_cancel" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the value returned by the call. If the call hasn’t yet
completed then this method will wait up to timeout seconds. If
the call hasn’t completed in timeout seconds, then the call is
cancelled and the method will return None.</p>
</dd></dl>
<span class="target" id="insertdocs-yoton-future-running"></span><dl class="method">
<dt id="yoton.Future.running">
<code class="descname">running</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#yoton.Future.running" title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if the call is currently being executed and cannot be
cancelled.</p>
</dd></dl>
<span class="target" id="insertdocs-yoton-future-set-auto-cancel-timeout"></span><dl class="method">
<dt id="yoton.Future.set_auto_cancel_timeout">
<code class="descname">set_auto_cancel_timeout</code><span class="sig-paren">(</span><em>timeout</em><span class="sig-paren">)</span><a class="headerlink" href="#yoton.Future.set_auto_cancel_timeout" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the timeout after which the call is automatically cancelled
if it is not done yet. By default, this value is 10 seconds.</p>
<p>If timeout is None, there is no limit to the wait time.</p>
</dd></dl>
<span class="target" id="insertdocs-yoton-future-set-exception"></span><dl class="method">
<dt id="yoton.Future.set_exception">
<code class="descname">set_exception</code><span class="sig-paren">(</span><em>exception</em><span class="sig-paren">)</span><a class="headerlink" href="#yoton.Future.set_exception" title="Permalink to this definition">¶</a></dt>
<dd><p>Sets the result of the work associated with the Future to the
Exception exception. This method should only be used by Executor
implementations and unit tests.</p>
</dd></dl>
<span class="target" id="insertdocs-yoton-future-set-result"></span><dl class="method">
<dt id="yoton.Future.set_result">
<code class="descname">set_result</code><span class="sig-paren">(</span><em>result</em><span class="sig-paren">)</span><a class="headerlink" href="#yoton.Future.set_result" title="Permalink to this definition">¶</a></dt>
<dd><p>Sets the result of the work associated with the Future to result.
This method should only be used by Executor implementations and
unit tests.</p>
</dd></dl>
<span class="target" id="insertdocs-yoton-future-set-running-or-notify-cancel"></span><dl class="method">
<dt id="yoton.Future.set_running_or_notify_cancel">
<code class="descname">set_running_or_notify_cancel</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#yoton.Future.set_running_or_notify_cancel" title="Permalink to this definition">¶</a></dt>
<dd><p>This method should only be called by Executor implementations before
executing the work associated with the Future and by unit tests.</p>
<p>If the method returns False then the Future was cancelled, i.e.
Future.cancel() was called and returned True.</p>
<p>If the method returns True then the Future was not cancelled and
has been put in the running state, i.e. calls to Future.running()
will return True.</p>
<p>This method can only be called once and cannot be called after
Future.set_result() or Future.set_exception() have been called.</p>
</dd></dl>
</dd></dl>
<span class="target" id="insertdocs-yoton-statechannel"></span><dl class="class">
<dt id="yoton.StateChannel">
<em class="property">class </em><code class="descclassname">yoton.</code><code class="descname">StateChannel</code><span class="sig-paren">(</span><em>context</em>, <em>slot_base</em>, <em>message_type=yoton.TEXT</em><span class="sig-paren">)</span><a class="headerlink" href="#yoton.StateChannel" title="Permalink to this definition">¶</a></dt>
<dd><p><em>Inherits from BaseChannel</em></p>
<p>Channel class for the state messaging pattern. A state is synchronized
over all state channels of the same slot. Each channel can
send (i.e. set) the state and recv (i.e. get) the current state.
Note however, that if two StateChannel instances set the state
around the same time, due to the network delay, it is undefined
which one sets the state the last.</p>
<p>The context will automatically call this channel’s send_last()
method when a new context enters the network.</p>
<p>The recv() call is always non-blocking and always returns the last
received message: i.e. the current state.</p>
<p>There are no limitations for this channel if events are not
processed, except that the received signal is not emitted.</p>
<p><strong>Parameters</strong></p>
<dl class="docutils">
<dt>context</dt>
<span class="classifier-delimiter">:</span> <span class="classifier"><a class="reference internal" href="context.html#insertdocs-yoton-context"><span class="std std-ref">yoton.Context</span></a> instance</span><dd>The context that this channel uses to send messages in a network.</dd>
<dt>slot_base</dt>
<span class="classifier-delimiter">:</span> <span class="classifier">string</span><dd>The base slot name. The channel appends an extension to indicate
message type and messaging pattern to create the final slot name.
The final slot is used to connect channels at different contexts
in a network</dd>
<dt>message_type</dt>
<span class="classifier-delimiter">:</span> <span class="classifier">yoton.MessageType instance</span><dd>(default is yoton.TEXT)
Object to convert messages to bytes and bytes to messages.
Users can create their own message_type class to let channels
any type of message they want.</dd>
</dl>
<p><em>METHODS</em></p>
<span class="target" id="insertdocs-yoton-statechannel-recv"></span><dl class="method">
<dt id="yoton.StateChannel.recv">
<code class="descname">recv</code><span class="sig-paren">(</span><em>block=False</em><span class="sig-paren">)</span><a class="headerlink" href="#yoton.StateChannel.recv" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the state of the channel. Always non-blocking. Returns the
most up to date state.</p>
</dd></dl>
<span class="target" id="insertdocs-yoton-statechannel-send"></span><dl class="method">
<dt id="yoton.StateChannel.send">
<code class="descname">send</code><span class="sig-paren">(</span><em>message</em><span class="sig-paren">)</span><a class="headerlink" href="#yoton.StateChannel.send" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the state of this channel.</p>
<p>The state-message is queued and send over the socket by the IO-thread.
Zero-length messages are ignored.</p>
</dd></dl>
<span class="target" id="insertdocs-yoton-statechannel-send-last"></span><dl class="method">
<dt id="yoton.StateChannel.send_last">
<code class="descname">send_last</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#yoton.StateChannel.send_last" title="Permalink to this definition">¶</a></dt>
<dd><p>Resend the last message.</p>
</dd></dl>
</dd></dl>
</div>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="../index.html">Table Of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">Channels</a><ul>
<li><a class="reference internal" href="#slots">Slots</a></li>
<li><a class="reference internal" href="#messaging-patterns">Messaging patterns</a></li>
<li><a class="reference internal" href="#message-types">Message types</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="connection.html"
title="previous chapter">Connection</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="events.html"
title="next chapter">Event system</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../_sources/yoton/channels.txt"
rel="nofollow">Show Source</a></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="../search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="events.html" title="Event system"
>next</a> |</li>
<li class="right" >
<a href="connection.html" title="Connection"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Pyzo 3.4 documentation</a> »</li>
<li class="nav-item nav-item-1"><a href="index.html" >Yoton - Inter process communication</a> »</li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2019, Pyzo contributors.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.9.
</div>
</body>
</html>
|