/usr/share/doc/python-pykka/html/api.html is in python-pykka 1.2.1-2.
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 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 | <!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>Pykka API — Pykka 1.2.1 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: '1.2.1',
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="top" title="Pykka 1.2.1 documentation" href="index.html" />
<link rel="next" title="Changes" href="changes.html" />
<link rel="prev" title="Pykka" href="index.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="changes.html" title="Changes"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="index.html" title="Pykka"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Pykka 1.2.1 documentation</a> »</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="module-pykka">
<span id="pykka-api"></span><h1>Pykka API<a class="headerlink" href="#module-pykka" title="Permalink to this headline">¶</a></h1>
<dl class="attribute">
<dt id="pykka.__version__">
<code class="descclassname">pykka.</code><code class="descname">__version__</code><a class="headerlink" href="#pykka.__version__" title="Permalink to this definition">¶</a></dt>
<dd><p>Pykka’s <span class="target" id="index-0"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0386"><strong>PEP 386</strong></a> and <span class="target" id="index-1"></span><a class="pep reference external" href="https://www.python.org/dev/peps/pep-0396"><strong>PEP 396</strong></a> compatible version number</p>
</dd></dl>
<div class="section" id="actors">
<h2>Actors<a class="headerlink" href="#actors" title="Permalink to this headline">¶</a></h2>
<dl class="exception">
<dt id="pykka.ActorDeadError">
<em class="property">exception </em><code class="descclassname">pykka.</code><code class="descname">ActorDeadError</code><a class="reference internal" href="_modules/pykka/exceptions.html#ActorDeadError"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.ActorDeadError" title="Permalink to this definition">¶</a></dt>
<dd><p>Exception raised when trying to use a dead or unavailable actor.</p>
</dd></dl>
<dl class="class">
<dt id="pykka.Actor">
<em class="property">class </em><code class="descclassname">pykka.</code><code class="descname">Actor</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/actor.html#Actor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.Actor" title="Permalink to this definition">¶</a></dt>
<dd><p>To create an actor:</p>
<ol class="arabic simple">
<li>subclass one of the <a class="reference internal" href="#pykka.Actor" title="pykka.Actor"><code class="xref py py-class docutils literal"><span class="pre">Actor</span></code></a> implementations, e.g.
<a class="reference internal" href="#pykka.gevent.GeventActor" title="pykka.gevent.GeventActor"><code class="xref py py-class docutils literal"><span class="pre">GeventActor</span></code></a> or
<a class="reference internal" href="#pykka.ThreadingActor" title="pykka.ThreadingActor"><code class="xref py py-class docutils literal"><span class="pre">ThreadingActor</span></code></a>,</li>
<li>implement your methods, including <code class="xref py py-meth docutils literal"><span class="pre">__init__()</span></code>, as usual,</li>
<li>call <a class="reference internal" href="#pykka.Actor.start" title="pykka.Actor.start"><code class="xref py py-meth docutils literal"><span class="pre">Actor.start()</span></code></a> on your actor class, passing the method any
arguments for your constructor.</li>
</ol>
<p>To stop an actor, call <a class="reference internal" href="#pykka.Actor.stop" title="pykka.Actor.stop"><code class="xref py py-meth docutils literal"><span class="pre">Actor.stop()</span></code></a> or <a class="reference internal" href="#pykka.ActorRef.stop" title="pykka.ActorRef.stop"><code class="xref py py-meth docutils literal"><span class="pre">ActorRef.stop()</span></code></a>.</p>
<p>For example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">pykka</span>
<span class="k">class</span> <span class="nc">MyActor</span><span class="p">(</span><span class="n">pykka</span><span class="o">.</span><span class="n">ThreadingActor</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">my_arg</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">MyActor</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">()</span>
<span class="o">...</span> <span class="c"># My optional init code with access to start() arguments</span>
<span class="k">def</span> <span class="nf">on_start</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="o">...</span> <span class="c"># My optional setup code in same context as on_receive()</span>
<span class="k">def</span> <span class="nf">on_stop</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="o">...</span> <span class="c"># My optional cleanup code in same context as on_receive()</span>
<span class="k">def</span> <span class="nf">on_failure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">exception_type</span><span class="p">,</span> <span class="n">exception_value</span><span class="p">,</span> <span class="n">traceback</span><span class="p">):</span>
<span class="o">...</span> <span class="c"># My optional cleanup code in same context as on_receive()</span>
<span class="k">def</span> <span class="nf">on_receive</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">message</span><span class="p">):</span>
<span class="o">...</span> <span class="c"># My optional message handling code for a plain actor</span>
<span class="k">def</span> <span class="nf">a_method</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">...</span><span class="p">):</span>
<span class="o">...</span> <span class="c"># My regular method to be used through an ActorProxy</span>
<span class="n">my_actor_ref</span> <span class="o">=</span> <span class="n">MyActor</span><span class="o">.</span><span class="n">start</span><span class="p">(</span><span class="n">my_arg</span><span class="o">=...</span><span class="p">)</span>
<span class="n">my_actor_ref</span><span class="o">.</span><span class="n">stop</span><span class="p">()</span>
</pre></div>
</div>
<dl class="classmethod">
<dt id="pykka.Actor.start">
<em class="property">classmethod </em><code class="descname">start</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/actor.html#Actor.start"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.Actor.start" title="Permalink to this definition">¶</a></dt>
<dd><p>Start an actor and register it in the
<a class="reference internal" href="#pykka.ActorRegistry" title="pykka.ActorRegistry"><code class="xref py py-class docutils literal"><span class="pre">ActorRegistry</span></code></a>.</p>
<p>Any arguments passed to <a class="reference internal" href="#pykka.Actor.start" title="pykka.Actor.start"><code class="xref py py-meth docutils literal"><span class="pre">start()</span></code></a> will be passed on to the class
constructor.</p>
<p>Behind the scenes, the following is happening when you call
<a class="reference internal" href="#pykka.Actor.start" title="pykka.Actor.start"><code class="xref py py-meth docutils literal"><span class="pre">start()</span></code></a>:</p>
<ol class="arabic simple">
<li>The actor is created:<ol class="arabic">
<li><a class="reference internal" href="#pykka.Actor.actor_urn" title="pykka.Actor.actor_urn"><code class="xref py py-attr docutils literal"><span class="pre">actor_urn</span></code></a> is initialized with the assigned URN.</li>
<li><a class="reference internal" href="#pykka.Actor.actor_inbox" title="pykka.Actor.actor_inbox"><code class="xref py py-attr docutils literal"><span class="pre">actor_inbox</span></code></a> is initialized with a new actor inbox.</li>
<li><a class="reference internal" href="#pykka.Actor.actor_ref" title="pykka.Actor.actor_ref"><code class="xref py py-attr docutils literal"><span class="pre">actor_ref</span></code></a> is initialized with a <a class="reference internal" href="#pykka.ActorRef" title="pykka.ActorRef"><code class="xref py py-class docutils literal"><span class="pre">pykka.ActorRef</span></code></a>
object for safely communicating with the actor.</li>
<li>At this point, your <code class="xref py py-meth docutils literal"><span class="pre">__init__()</span></code> code can run.</li>
</ol>
</li>
<li>The actor is registered in <a class="reference internal" href="#pykka.ActorRegistry" title="pykka.ActorRegistry"><code class="xref py py-class docutils literal"><span class="pre">pykka.ActorRegistry</span></code></a>.</li>
<li>The actor receive loop is started by the actor’s associated
thread/greenlet.</li>
</ol>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">a <a class="reference internal" href="#pykka.ActorRef" title="pykka.ActorRef"><code class="xref py py-class docutils literal"><span class="pre">ActorRef</span></code></a> which can be used to access the actor in
a safe manner</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="attribute">
<dt id="pykka.Actor.actor_urn">
<code class="descname">actor_urn</code><em class="property"> = None</em><a class="headerlink" href="#pykka.Actor.actor_urn" title="Permalink to this definition">¶</a></dt>
<dd><p>The actor URN string is a universally unique identifier for the actor.
It may be used for looking up a specific actor using
<a class="reference internal" href="#pykka.ActorRegistry.get_by_urn" title="pykka.ActorRegistry.get_by_urn"><code class="xref py py-meth docutils literal"><span class="pre">ActorRegistry.get_by_urn</span></code></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="pykka.Actor.actor_inbox">
<code class="descname">actor_inbox</code><em class="property"> = None</em><a class="headerlink" href="#pykka.Actor.actor_inbox" title="Permalink to this definition">¶</a></dt>
<dd><p>The actor’s inbox. Use <a class="reference internal" href="#pykka.ActorRef.tell" title="pykka.ActorRef.tell"><code class="xref py py-meth docutils literal"><span class="pre">ActorRef.tell()</span></code></a>, <a class="reference internal" href="#pykka.ActorRef.ask" title="pykka.ActorRef.ask"><code class="xref py py-meth docutils literal"><span class="pre">ActorRef.ask()</span></code></a>, and
friends to put messages in the inbox.</p>
</dd></dl>
<dl class="attribute">
<dt id="pykka.Actor.actor_stopped">
<code class="descname">actor_stopped</code><em class="property"> = None</em><a class="headerlink" href="#pykka.Actor.actor_stopped" title="Permalink to this definition">¶</a></dt>
<dd><p>A <code class="xref py py-class docutils literal"><span class="pre">threading.Event</span></code> representing whether or not the actor should
continue processing messages. Use <a class="reference internal" href="#pykka.Actor.stop" title="pykka.Actor.stop"><code class="xref py py-meth docutils literal"><span class="pre">stop()</span></code></a> to change it.</p>
</dd></dl>
<dl class="attribute">
<dt id="pykka.Actor.actor_ref">
<code class="descname">actor_ref</code><em class="property"> = None</em><a class="headerlink" href="#pykka.Actor.actor_ref" title="Permalink to this definition">¶</a></dt>
<dd><p>The actor’s <a class="reference internal" href="#pykka.ActorRef" title="pykka.ActorRef"><code class="xref py py-class docutils literal"><span class="pre">ActorRef</span></code></a> instance.</p>
</dd></dl>
<dl class="method">
<dt id="pykka.Actor.stop">
<code class="descname">stop</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/actor.html#Actor.stop"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.Actor.stop" title="Permalink to this definition">¶</a></dt>
<dd><p>Stop the actor.</p>
<p>It’s equivalent to calling <a class="reference internal" href="#pykka.ActorRef.stop" title="pykka.ActorRef.stop"><code class="xref py py-meth docutils literal"><span class="pre">ActorRef.stop()</span></code></a> with <code class="docutils literal"><span class="pre">block=False</span></code>.</p>
</dd></dl>
<dl class="method">
<dt id="pykka.Actor.on_start">
<code class="descname">on_start</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/actor.html#Actor.on_start"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.Actor.on_start" title="Permalink to this definition">¶</a></dt>
<dd><p>Hook for doing any setup that should be done <em>after</em> the actor is
started, but <em>before</em> it starts processing messages.</p>
<p>For <a class="reference internal" href="#pykka.ThreadingActor" title="pykka.ThreadingActor"><code class="xref py py-class docutils literal"><span class="pre">ThreadingActor</span></code></a>, this method is executed in the actor’s own
thread, while <code class="xref py py-meth docutils literal"><span class="pre">__init__()</span></code> is executed in the thread that created
the actor.</p>
<p>If an exception is raised by this method the stack trace will be
logged, and the actor will stop.</p>
</dd></dl>
<dl class="method">
<dt id="pykka.Actor.on_stop">
<code class="descname">on_stop</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/actor.html#Actor.on_stop"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.Actor.on_stop" title="Permalink to this definition">¶</a></dt>
<dd><p>Hook for doing any cleanup that should be done <em>after</em> the actor has
processed the last message, and <em>before</em> the actor stops.</p>
<p>This hook is <em>not</em> called when the actor stops because of an unhandled
exception. In that case, the <a class="reference internal" href="#pykka.Actor.on_failure" title="pykka.Actor.on_failure"><code class="xref py py-meth docutils literal"><span class="pre">on_failure()</span></code></a> hook is called instead.</p>
<p>For <a class="reference internal" href="#pykka.ThreadingActor" title="pykka.ThreadingActor"><code class="xref py py-class docutils literal"><span class="pre">ThreadingActor</span></code></a> this method is executed in the actor’s own
thread, immediately before the thread exits.</p>
<p>If an exception is raised by this method the stack trace will be
logged, and the actor will stop.</p>
</dd></dl>
<dl class="method">
<dt id="pykka.Actor.on_failure">
<code class="descname">on_failure</code><span class="sig-paren">(</span><em>exception_type</em>, <em>exception_value</em>, <em>traceback</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/actor.html#Actor.on_failure"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.Actor.on_failure" title="Permalink to this definition">¶</a></dt>
<dd><p>Hook for doing any cleanup <em>after</em> an unhandled exception is raised,
and <em>before</em> the actor stops.</p>
<p>For <a class="reference internal" href="#pykka.ThreadingActor" title="pykka.ThreadingActor"><code class="xref py py-class docutils literal"><span class="pre">ThreadingActor</span></code></a> this method is executed in the actor’s own
thread, immediately before the thread exits.</p>
<p>The method’s arguments are the relevant information from
<code class="xref py py-func docutils literal"><span class="pre">sys.exc_info()</span></code>.</p>
<p>If an exception is raised by this method the stack trace will be
logged, and the actor will stop.</p>
</dd></dl>
<dl class="method">
<dt id="pykka.Actor.on_receive">
<code class="descname">on_receive</code><span class="sig-paren">(</span><em>message</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/actor.html#Actor.on_receive"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.Actor.on_receive" title="Permalink to this definition">¶</a></dt>
<dd><p>May be implemented for the actor to handle regular non-proxy messages.</p>
<p>Messages where the value of the “command” key matches “pykka_*” are
reserved for internal use in Pykka.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>message</strong> (<em>picklable dict</em>) – the message to handle</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">anything that should be sent as a reply to the sender</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="pykka.ThreadingActor">
<em class="property">class </em><code class="descclassname">pykka.</code><code class="descname">ThreadingActor</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/threading.html#ThreadingActor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.ThreadingActor" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#pykka.ThreadingActor" title="pykka.ThreadingActor"><code class="xref py py-class docutils literal"><span class="pre">ThreadingActor</span></code></a> implements <a class="reference internal" href="#pykka.Actor" title="pykka.Actor"><code class="xref py py-class docutils literal"><span class="pre">Actor</span></code></a> using regular Python
threads.</p>
<p>This implementation is slower than <a class="reference internal" href="#pykka.gevent.GeventActor" title="pykka.gevent.GeventActor"><code class="xref py py-class docutils literal"><span class="pre">GeventActor</span></code></a>, but can be used in a process with other
threads that are not Pykka actors.</p>
<dl class="attribute">
<dt id="pykka.ThreadingActor.use_daemon_thread">
<code class="descname">use_daemon_thread</code><em class="property"> = False</em><a class="headerlink" href="#pykka.ThreadingActor.use_daemon_thread" title="Permalink to this definition">¶</a></dt>
<dd><p>A boolean value indicating whether this actor is executed on a thread that
is a daemon thread (<code class="xref py py-class docutils literal"><span class="pre">True</span></code>) or not (<code class="xref py py-class docutils literal"><span class="pre">False</span></code>). This must be
set before <a class="reference internal" href="#pykka.Actor.start" title="pykka.Actor.start"><code class="xref py py-meth docutils literal"><span class="pre">pykka.Actor.start()</span></code></a> is called, otherwise
<code class="xref py py-exc docutils literal"><span class="pre">RuntimeError</span></code> is raised.</p>
<p>The entire Python program exits when no alive non-daemon threads are left.
This means that an actor running on a daemon thread may be interrupted at
any time, and there is no guarantee that cleanup will be done or that
<a class="reference internal" href="#pykka.Actor.on_stop" title="pykka.Actor.on_stop"><code class="xref py py-meth docutils literal"><span class="pre">pykka.Actor.on_stop()</span></code></a> will be called.</p>
<p>Actors do not inherit the daemon flag from the actor that made it. It
always has to be set explicitly for the actor to run on a daemonic thread.</p>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="pykka.ActorRef">
<em class="property">class </em><code class="descclassname">pykka.</code><code class="descname">ActorRef</code><span class="sig-paren">(</span><em>actor</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/actor.html#ActorRef"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.ActorRef" title="Permalink to this definition">¶</a></dt>
<dd><p>Reference to a running actor which may safely be passed around.</p>
<p><a class="reference internal" href="#pykka.ActorRef" title="pykka.ActorRef"><code class="xref py py-class docutils literal"><span class="pre">ActorRef</span></code></a> instances are returned by <a class="reference internal" href="#pykka.Actor.start" title="pykka.Actor.start"><code class="xref py py-meth docutils literal"><span class="pre">Actor.start()</span></code></a> and the
lookup methods in <a class="reference internal" href="#pykka.ActorRegistry" title="pykka.ActorRegistry"><code class="xref py py-class docutils literal"><span class="pre">ActorRegistry</span></code></a>. You should
never need to create <a class="reference internal" href="#pykka.ActorRef" title="pykka.ActorRef"><code class="xref py py-class docutils literal"><span class="pre">ActorRef</span></code></a> instances yourself.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>actor</strong> (<a class="reference internal" href="#pykka.Actor" title="pykka.Actor"><code class="xref py py-class docutils literal"><span class="pre">Actor</span></code></a>) – the actor to wrap</td>
</tr>
</tbody>
</table>
<dl class="attribute">
<dt id="pykka.ActorRef.actor_class">
<code class="descname">actor_class</code><em class="property"> = None</em><a class="headerlink" href="#pykka.ActorRef.actor_class" title="Permalink to this definition">¶</a></dt>
<dd><p>The class of the referenced actor.</p>
</dd></dl>
<dl class="attribute">
<dt id="pykka.ActorRef.actor_urn">
<code class="descname">actor_urn</code><em class="property"> = None</em><a class="headerlink" href="#pykka.ActorRef.actor_urn" title="Permalink to this definition">¶</a></dt>
<dd><p>See <a class="reference internal" href="#pykka.Actor.actor_urn" title="pykka.Actor.actor_urn"><code class="xref py py-attr docutils literal"><span class="pre">Actor.actor_urn</span></code></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="pykka.ActorRef.actor_inbox">
<code class="descname">actor_inbox</code><em class="property"> = None</em><a class="headerlink" href="#pykka.ActorRef.actor_inbox" title="Permalink to this definition">¶</a></dt>
<dd><p>See <a class="reference internal" href="#pykka.Actor.actor_inbox" title="pykka.Actor.actor_inbox"><code class="xref py py-attr docutils literal"><span class="pre">Actor.actor_inbox</span></code></a>.</p>
</dd></dl>
<dl class="attribute">
<dt id="pykka.ActorRef.actor_stopped">
<code class="descname">actor_stopped</code><em class="property"> = None</em><a class="headerlink" href="#pykka.ActorRef.actor_stopped" title="Permalink to this definition">¶</a></dt>
<dd><p>See <a class="reference internal" href="#pykka.Actor.actor_stopped" title="pykka.Actor.actor_stopped"><code class="xref py py-attr docutils literal"><span class="pre">Actor.actor_stopped</span></code></a>.</p>
</dd></dl>
<dl class="method">
<dt id="pykka.ActorRef.is_alive">
<code class="descname">is_alive</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/actor.html#ActorRef.is_alive"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.ActorRef.is_alive" title="Permalink to this definition">¶</a></dt>
<dd><p>Check if actor is alive.</p>
<p>This is based on the actor’s stopped flag. The actor is not guaranteed
to be alive and responding even though <a class="reference internal" href="#pykka.ActorRef.is_alive" title="pykka.ActorRef.is_alive"><code class="xref py py-meth docutils literal"><span class="pre">is_alive()</span></code></a> returns
<code class="xref py py-class docutils literal"><span class="pre">True</span></code>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">Returns <code class="xref py py-class docutils literal"><span class="pre">True</span></code> if actor is alive, <code class="xref py py-class docutils literal"><span class="pre">False</span></code> otherwise.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="pykka.ActorRef.tell">
<code class="descname">tell</code><span class="sig-paren">(</span><em>message</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/actor.html#ActorRef.tell"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.ActorRef.tell" title="Permalink to this definition">¶</a></dt>
<dd><p>Send message to actor without waiting for any response.</p>
<p>Will generally not block, but if the underlying queue is full it will
block until a free slot is available.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>message</strong> (<em>picklable dict</em>) – message to send</td>
</tr>
<tr class="field-even field"><th class="field-name">Raise:</th><td class="field-body"><a class="reference internal" href="#pykka.ActorDeadError" title="pykka.ActorDeadError"><code class="xref py py-exc docutils literal"><span class="pre">pykka.ActorDeadError</span></code></a> if actor is not available</td>
</tr>
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">nothing</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="pykka.ActorRef.ask">
<code class="descname">ask</code><span class="sig-paren">(</span><em>message</em>, <em>block=True</em>, <em>timeout=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/actor.html#ActorRef.ask"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.ActorRef.ask" title="Permalink to this definition">¶</a></dt>
<dd><p>Send message to actor and wait for the reply.</p>
<p>The message must be a picklable dict.
If <code class="docutils literal"><span class="pre">block</span></code> is <code class="xref py py-class docutils literal"><span class="pre">False</span></code>, it will immediately return a
<a class="reference internal" href="#pykka.Future" title="pykka.Future"><code class="xref py py-class docutils literal"><span class="pre">Future</span></code></a> instead of blocking.</p>
<p>If <code class="docutils literal"><span class="pre">block</span></code> is <code class="xref py py-class docutils literal"><span class="pre">True</span></code>, and <code class="docutils literal"><span class="pre">timeout</span></code> is <code class="xref py py-class docutils literal"><span class="pre">None</span></code>, as
default, the method will block until it gets a reply, potentially
forever. If <code class="docutils literal"><span class="pre">timeout</span></code> is an integer or float, the method will wait
for a reply for <code class="docutils literal"><span class="pre">timeout</span></code> seconds, and then raise
<a class="reference internal" href="#pykka.Timeout" title="pykka.Timeout"><code class="xref py py-exc docutils literal"><span class="pre">pykka.Timeout</span></code></a>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>message</strong> (<em>picklable dict</em>) – message to send</li>
<li><strong>block</strong> (<em>boolean</em>) – whether to block while waiting for a reply</li>
<li><strong>timeout</strong> (float or <code class="xref py py-class docutils literal"><span class="pre">None</span></code>) – seconds to wait before timeout if blocking</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Raise:</th><td class="field-body"><p class="first"><a class="reference internal" href="#pykka.Timeout" title="pykka.Timeout"><code class="xref py py-exc docutils literal"><span class="pre">pykka.Timeout</span></code></a> if timeout is reached if blocking</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Raise:</th><td class="field-body"><p class="first">any exception returned by the receiving actor if blocking</p>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last"><a class="reference internal" href="#pykka.Future" title="pykka.Future"><code class="xref py py-class docutils literal"><span class="pre">pykka.Future</span></code></a>, or response if blocking</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="pykka.ActorRef.stop">
<code class="descname">stop</code><span class="sig-paren">(</span><em>block=True</em>, <em>timeout=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/actor.html#ActorRef.stop"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.ActorRef.stop" title="Permalink to this definition">¶</a></dt>
<dd><p>Send a message to the actor, asking it to stop.</p>
<p>Returns <code class="xref py py-class docutils literal"><span class="pre">True</span></code> if actor is stopped or was being stopped at the
time of the call. <code class="xref py py-class docutils literal"><span class="pre">False</span></code> if actor was already dead. If
<code class="docutils literal"><span class="pre">block</span></code> is <code class="xref py py-class docutils literal"><span class="pre">False</span></code>, it returns a future wrapping the result.</p>
<p>Messages sent to the actor before the actor is asked to stop will
be processed normally before it stops.</p>
<p>Messages sent to the actor after the actor is asked to stop will
be replied to with <a class="reference internal" href="#pykka.ActorDeadError" title="pykka.ActorDeadError"><code class="xref py py-exc docutils literal"><span class="pre">pykka.ActorDeadError</span></code></a> after it stops.</p>
<p>The actor may not be restarted.</p>
<p><code class="docutils literal"><span class="pre">block</span></code> and <code class="docutils literal"><span class="pre">timeout</span></code> works as for <a class="reference internal" href="#pykka.ActorRef.ask" title="pykka.ActorRef.ask"><code class="xref py py-meth docutils literal"><span class="pre">ask()</span></code></a>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><a class="reference internal" href="#pykka.Future" title="pykka.Future"><code class="xref py py-class docutils literal"><span class="pre">pykka.Future</span></code></a>, or a boolean result if blocking</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="pykka.ActorRef.proxy">
<code class="descname">proxy</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/actor.html#ActorRef.proxy"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.ActorRef.proxy" title="Permalink to this definition">¶</a></dt>
<dd><p>Wraps the <a class="reference internal" href="#pykka.ActorRef" title="pykka.ActorRef"><code class="xref py py-class docutils literal"><span class="pre">ActorRef</span></code></a> in an <a class="reference internal" href="#pykka.ActorProxy" title="pykka.ActorProxy"><code class="xref py py-class docutils literal"><span class="pre">ActorProxy</span></code></a>.</p>
<p>Using this method like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">proxy</span> <span class="o">=</span> <span class="n">AnActor</span><span class="o">.</span><span class="n">start</span><span class="p">()</span><span class="o">.</span><span class="n">proxy</span><span class="p">()</span>
</pre></div>
</div>
<p>is analogous to:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">proxy</span> <span class="o">=</span> <span class="n">ActorProxy</span><span class="p">(</span><span class="n">AnActor</span><span class="o">.</span><span class="n">start</span><span class="p">())</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Raise:</th><td class="field-body"><a class="reference internal" href="#pykka.ActorDeadError" title="pykka.ActorDeadError"><code class="xref py py-exc docutils literal"><span class="pre">pykka.ActorDeadError</span></code></a> if actor is not available</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><a class="reference internal" href="#pykka.ActorProxy" title="pykka.ActorProxy"><code class="xref py py-class docutils literal"><span class="pre">pykka.ActorProxy</span></code></a></td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="proxies">
<h2>Proxies<a class="headerlink" href="#proxies" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="pykka.ActorProxy">
<em class="property">class </em><code class="descclassname">pykka.</code><code class="descname">ActorProxy</code><span class="sig-paren">(</span><em>actor_ref</em>, <em>attr_path=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/proxy.html#ActorProxy"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.ActorProxy" title="Permalink to this definition">¶</a></dt>
<dd><p>An <a class="reference internal" href="#pykka.ActorProxy" title="pykka.ActorProxy"><code class="xref py py-class docutils literal"><span class="pre">ActorProxy</span></code></a> wraps an <a class="reference internal" href="#pykka.ActorRef" title="pykka.ActorRef"><code class="xref py py-class docutils literal"><span class="pre">ActorRef</span></code></a>
instance. The proxy allows the referenced actor to be used through regular
method calls and field access.</p>
<p>You can create an <a class="reference internal" href="#pykka.ActorProxy" title="pykka.ActorProxy"><code class="xref py py-class docutils literal"><span class="pre">ActorProxy</span></code></a> from any <a class="reference internal" href="#pykka.ActorRef" title="pykka.ActorRef"><code class="xref py py-class docutils literal"><span class="pre">ActorRef</span></code></a>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">actor_ref</span> <span class="o">=</span> <span class="n">MyActor</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
<span class="n">actor_proxy</span> <span class="o">=</span> <span class="n">ActorProxy</span><span class="p">(</span><span class="n">actor_ref</span><span class="p">)</span>
</pre></div>
</div>
<p>You can also get an <a class="reference internal" href="#pykka.ActorProxy" title="pykka.ActorProxy"><code class="xref py py-class docutils literal"><span class="pre">ActorProxy</span></code></a> by using <a class="reference internal" href="#pykka.ActorRef.proxy" title="pykka.ActorRef.proxy"><code class="xref py py-meth docutils literal"><span class="pre">proxy()</span></code></a>:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">actor_proxy</span> <span class="o">=</span> <span class="n">MyActor</span><span class="o">.</span><span class="n">start</span><span class="p">()</span><span class="o">.</span><span class="n">proxy</span><span class="p">()</span>
</pre></div>
</div>
<p>When reading an attribute or getting a return value from a method, you get
a <a class="reference internal" href="#pykka.Future" title="pykka.Future"><code class="xref py py-class docutils literal"><span class="pre">Future</span></code></a> object back. To get the enclosed value
from the future, you must call <a class="reference internal" href="#pykka.Future.get" title="pykka.Future.get"><code class="xref py py-meth docutils literal"><span class="pre">get()</span></code></a> on the
returned future:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">print</span> <span class="n">actor_proxy</span><span class="o">.</span><span class="n">string_attribute</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<span class="k">print</span> <span class="n">actor_proxy</span><span class="o">.</span><span class="n">count</span><span class="p">()</span><span class="o">.</span><span class="n">get</span><span class="p">()</span> <span class="o">+</span> <span class="mi">1</span>
</pre></div>
</div>
<p>If you call a method just for it’s side effects and do not care about the
return value, you do not need to accept the returned future or call
<a class="reference internal" href="#pykka.Future.get" title="pykka.Future.get"><code class="xref py py-meth docutils literal"><span class="pre">get()</span></code></a> on the future. Simply call the method, and
it will be executed concurrently with your own code:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">actor_proxy</span><span class="o">.</span><span class="n">method_with_side_effect</span><span class="p">()</span>
</pre></div>
</div>
<p>If you want to block your own code from continuing while the other method
is processing, you can use <a class="reference internal" href="#pykka.Future.get" title="pykka.Future.get"><code class="xref py py-meth docutils literal"><span class="pre">get()</span></code></a> to block until
it completes:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">actor_proxy</span><span class="o">.</span><span class="n">method_with_side_effect</span><span class="p">()</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
</pre></div>
</div>
<p>An actor can use a proxy to itself to schedule work for itself. The
scheduled work will only be done after the current message and all messages
already in the inbox are processed.</p>
<p>For example, if an actor can split a time consuming task into multiple
parts, and after completing each part can ask itself to start on the next
part using proxied calls or messages to itself, it can react faster to
other incoming messages as they will be interleaved with the parts of the
time consuming task. This is especially useful for being able to stop the
actor in the middle of a time consuming task.</p>
<p>To create a proxy to yourself, use the actor’s <a class="reference internal" href="#pykka.Actor.actor_ref" title="pykka.Actor.actor_ref"><code class="xref py py-attr docutils literal"><span class="pre">actor_ref</span></code></a> attribute:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">proxy_to_myself_in_the_future</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">actor_ref</span><span class="o">.</span><span class="n">proxy</span><span class="p">()</span>
</pre></div>
</div>
<p>If you create a proxy in your actor’s constructor or <a class="reference internal" href="#pykka.Actor.on_start" title="pykka.Actor.on_start"><code class="xref py py-meth docutils literal"><span class="pre">on_start</span></code></a> method, you can create a nice API for deferring
work to yourself in the future:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="o">...</span>
<span class="bp">self</span><span class="o">.</span><span class="n">in_future</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">actor_ref</span><span class="o">.</span><span class="n">proxy</span><span class="p">()</span>
<span class="o">...</span>
<span class="k">def</span> <span class="nf">do_work</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="o">...</span>
<span class="bp">self</span><span class="o">.</span><span class="n">in_future</span><span class="o">.</span><span class="n">do_more_work</span><span class="p">()</span>
<span class="o">...</span>
<span class="k">def</span> <span class="nf">do_more_work</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="o">...</span>
</pre></div>
</div>
<p>An example of <a class="reference internal" href="#pykka.ActorProxy" title="pykka.ActorProxy"><code class="xref py py-class docutils literal"><span class="pre">ActorProxy</span></code></a> usage:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c">#! /usr/bin/env python</span>
<span class="kn">import</span> <span class="nn">pykka</span>
<span class="k">class</span> <span class="nc">Adder</span><span class="p">(</span><span class="n">pykka</span><span class="o">.</span><span class="n">ThreadingActor</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">add_one</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="p">):</span>
<span class="k">print</span><span class="p">(</span><span class="s">'{} is increasing {}'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="p">))</span>
<span class="k">return</span> <span class="n">i</span> <span class="o">+</span> <span class="mi">1</span>
<span class="k">class</span> <span class="nc">Bookkeeper</span><span class="p">(</span><span class="n">pykka</span><span class="o">.</span><span class="n">ThreadingActor</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">adder</span><span class="p">):</span>
<span class="nb">super</span><span class="p">(</span><span class="n">Bookkeeper</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">adder</span> <span class="o">=</span> <span class="n">adder</span>
<span class="k">def</span> <span class="nf">count_to</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">target</span><span class="p">):</span>
<span class="n">i</span> <span class="o">=</span> <span class="mi">0</span>
<span class="k">while</span> <span class="n">i</span> <span class="o"><</span> <span class="n">target</span><span class="p">:</span>
<span class="n">i</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">adder</span><span class="o">.</span><span class="n">add_one</span><span class="p">(</span><span class="n">i</span><span class="p">)</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<span class="k">print</span><span class="p">(</span><span class="s">'{} got {} back'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="p">))</span>
<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">'__main__'</span><span class="p">:</span>
<span class="n">adder</span> <span class="o">=</span> <span class="n">Adder</span><span class="o">.</span><span class="n">start</span><span class="p">()</span><span class="o">.</span><span class="n">proxy</span><span class="p">()</span>
<span class="n">bookkeeper</span> <span class="o">=</span> <span class="n">Bookkeeper</span><span class="o">.</span><span class="n">start</span><span class="p">(</span><span class="n">adder</span><span class="p">)</span><span class="o">.</span><span class="n">proxy</span><span class="p">()</span>
<span class="n">bookkeeper</span><span class="o">.</span><span class="n">count_to</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<span class="n">pykka</span><span class="o">.</span><span class="n">ActorRegistry</span><span class="o">.</span><span class="n">stop_all</span><span class="p">()</span>
</pre></div>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>actor_ref</strong> (<a class="reference internal" href="#pykka.ActorRef" title="pykka.ActorRef"><code class="xref py py-class docutils literal"><span class="pre">pykka.ActorRef</span></code></a>) – reference to the actor to proxy</td>
</tr>
<tr class="field-even field"><th class="field-name">Raise:</th><td class="field-body"><a class="reference internal" href="#pykka.ActorDeadError" title="pykka.ActorDeadError"><code class="xref py py-exc docutils literal"><span class="pre">pykka.ActorDeadError</span></code></a> if actor is not available</td>
</tr>
</tbody>
</table>
<dl class="attribute">
<dt id="pykka.ActorProxy.actor_ref">
<code class="descname">actor_ref</code><em class="property"> = None</em><a class="headerlink" href="#pykka.ActorProxy.actor_ref" title="Permalink to this definition">¶</a></dt>
<dd><p>The actor’s <a class="reference internal" href="#pykka.ActorRef" title="pykka.ActorRef"><code class="xref py py-class docutils literal"><span class="pre">pykka.ActorRef</span></code></a> instance.</p>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="futures">
<h2>Futures<a class="headerlink" href="#futures" title="Permalink to this headline">¶</a></h2>
<dl class="exception">
<dt id="pykka.Timeout">
<em class="property">exception </em><code class="descclassname">pykka.</code><code class="descname">Timeout</code><a class="reference internal" href="_modules/pykka/exceptions.html#Timeout"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.Timeout" title="Permalink to this definition">¶</a></dt>
<dd><p>Exception raised at future timeout.</p>
</dd></dl>
<dl class="class">
<dt id="pykka.Future">
<em class="property">class </em><code class="descclassname">pykka.</code><code class="descname">Future</code><a class="reference internal" href="_modules/pykka/future.html#Future"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.Future" title="Permalink to this definition">¶</a></dt>
<dd><p>A <a class="reference internal" href="#pykka.Future" title="pykka.Future"><code class="xref py py-class docutils literal"><span class="pre">Future</span></code></a> is a handle to a value which are available or will be
available in the future.</p>
<p>Typically returned by calls to actor methods or accesses to actor fields.</p>
<p>To get hold of the encapsulated value, call <a class="reference internal" href="#pykka.Future.get" title="pykka.Future.get"><code class="xref py py-meth docutils literal"><span class="pre">Future.get()</span></code></a>.</p>
<dl class="method">
<dt id="pykka.Future.get">
<code class="descname">get</code><span class="sig-paren">(</span><em>timeout=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/future.html#Future.get"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.Future.get" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the value encapsulated by the future.</p>
<p>If the encapsulated value is an exception, it is raised instead of
returned.</p>
<p>If <code class="docutils literal"><span class="pre">timeout</span></code> is <code class="xref py py-class docutils literal"><span class="pre">None</span></code>, as default, the method will block
until it gets a reply, potentially forever. If <code class="docutils literal"><span class="pre">timeout</span></code> is an
integer or float, the method will wait for a reply for <code class="docutils literal"><span class="pre">timeout</span></code>
seconds, and then raise <a class="reference internal" href="#pykka.Timeout" title="pykka.Timeout"><code class="xref py py-exc docutils literal"><span class="pre">pykka.Timeout</span></code></a>.</p>
<p>The encapsulated value can be retrieved multiple times. The future will
only block the first time the value is accessed.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>timeout</strong> (float or <code class="xref py py-class docutils literal"><span class="pre">None</span></code>) – seconds to wait before timeout</td>
</tr>
<tr class="field-even field"><th class="field-name">Raise:</th><td class="field-body"><a class="reference internal" href="#pykka.Timeout" title="pykka.Timeout"><code class="xref py py-exc docutils literal"><span class="pre">pykka.Timeout</span></code></a> if timeout is reached</td>
</tr>
<tr class="field-odd field"><th class="field-name">Raise:</th><td class="field-body">encapsulated value if it is an exception</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">encapsulated value if it is not an exception</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="pykka.Future.set">
<code class="descname">set</code><span class="sig-paren">(</span><em>value=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/future.html#Future.set"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.Future.set" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the encapsulated value.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>value</strong> (any picklable object or <code class="xref py py-class docutils literal"><span class="pre">None</span></code>) – the encapsulated value or nothing</td>
</tr>
<tr class="field-even field"><th class="field-name">Raise:</th><td class="field-body">an exception if set is called multiple times</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="pykka.Future.set_exception">
<code class="descname">set_exception</code><span class="sig-paren">(</span><em>exc_info=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/future.html#Future.set_exception"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.Future.set_exception" title="Permalink to this definition">¶</a></dt>
<dd><p>Set an exception as the encapsulated value.</p>
<p>You can pass an <code class="docutils literal"><span class="pre">exc_info</span></code> three-tuple, as returned by
<code class="xref py py-func docutils literal"><span class="pre">sys.exc_info()</span></code>. If you don’t pass <code class="docutils literal"><span class="pre">exc_info</span></code>,
<code class="xref py py-func docutils literal"><span class="pre">sys.exc_info()</span></code> will be called and the value returned by it used.</p>
<p>In other words, if you’re calling <a class="reference internal" href="#pykka.Future.set_exception" title="pykka.Future.set_exception"><code class="xref py py-meth docutils literal"><span class="pre">set_exception()</span></code></a>, without any
arguments, from an except block, the exception you’re currently
handling will automatically be set on the future.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.15: </span>Previously, <a class="reference internal" href="#pykka.Future.set_exception" title="pykka.Future.set_exception"><code class="xref py py-meth docutils literal"><span class="pre">set_exception()</span></code></a> accepted an exception
instance as its only argument. This still works, but it is
deprecated and will be removed in a future release.</p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>exc_info</strong> (<em>three-tuple of (exc_class, exc_instance, traceback)</em>) – the encapsulated exception</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="pykka.Future.set_get_hook">
<code class="descname">set_get_hook</code><span class="sig-paren">(</span><em>func</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/future.html#Future.set_get_hook"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.Future.set_get_hook" title="Permalink to this definition">¶</a></dt>
<dd><p>Set a function to be executed when <a class="reference internal" href="#pykka.Future.get" title="pykka.Future.get"><code class="xref py py-meth docutils literal"><span class="pre">get()</span></code></a> is called.</p>
<p>The function will be called when <a class="reference internal" href="#pykka.Future.get" title="pykka.Future.get"><code class="xref py py-meth docutils literal"><span class="pre">get()</span></code></a> is called, with the
<code class="docutils literal"><span class="pre">timeout</span></code> value as the only argument. The function’s return value
will be returned from <a class="reference internal" href="#pykka.Future.get" title="pykka.Future.get"><code class="xref py py-meth docutils literal"><span class="pre">get()</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.2.</span></p>
</div>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>func</strong> (<em>function accepting a timeout value</em>) – called to produce return value of <a class="reference internal" href="#pykka.Future.get" title="pykka.Future.get"><code class="xref py py-meth docutils literal"><span class="pre">get()</span></code></a></td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="method">
<dt id="pykka.Future.filter">
<code class="descname">filter</code><span class="sig-paren">(</span><em>func</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/future.html#Future.filter"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.Future.filter" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a new future with only the items passing the predicate function.</p>
<p>If the future’s value is an iterable, <a class="reference internal" href="#pykka.Future.filter" title="pykka.Future.filter"><code class="xref py py-meth docutils literal"><span class="pre">filter()</span></code></a> will return a new
future whose value is another iterable with only the items from the
first iterable for which <code class="docutils literal"><span class="pre">func(item)</span></code> is true. If the future’s value
isn’t an iterable, a <code class="xref py py-exc docutils literal"><span class="pre">TypeError</span></code> will be raised when <a class="reference internal" href="#pykka.Future.get" title="pykka.Future.get"><code class="xref py py-meth docutils literal"><span class="pre">get()</span></code></a>
is called.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">pykka</span>
<span class="gp">>>> </span><span class="n">f</span> <span class="o">=</span> <span class="n">pykka</span><span class="o">.</span><span class="n">ThreadingFuture</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">g</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span> <span class="o">></span> <span class="mi">10</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">g</span>
<span class="go"><pykka.future.ThreadingFuture at ...></span>
<span class="gp">>>> </span><span class="n">f</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">15</span><span class="p">))</span>
<span class="gp">>>> </span><span class="n">f</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<span class="go">[5, 6, 7, 8, 9, 10, 11, 12, 13, 14]</span>
<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<span class="go">[11, 12, 13, 14]</span>
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.2.</span></p>
</div>
</dd></dl>
<dl class="method">
<dt id="pykka.Future.join">
<code class="descname">join</code><span class="sig-paren">(</span><em>*futures</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/future.html#Future.join"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.Future.join" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a new future with a list of the result of multiple futures.</p>
<p>One or more futures can be passed as arguments to <a class="reference internal" href="#pykka.Future.join" title="pykka.Future.join"><code class="xref py py-meth docutils literal"><span class="pre">join()</span></code></a>. The new
future returns a list with the results from all the joined futures.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">pykka</span>
<span class="gp">>>> </span><span class="n">a</span> <span class="o">=</span> <span class="n">pykka</span><span class="o">.</span><span class="n">ThreadingFuture</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">b</span> <span class="o">=</span> <span class="n">pykka</span><span class="o">.</span><span class="n">ThreadingFuture</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">c</span> <span class="o">=</span> <span class="n">pykka</span><span class="o">.</span><span class="n">ThreadingFuture</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">f</span> <span class="o">=</span> <span class="n">a</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">c</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">a</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s">'def'</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">b</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="mi">123</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">c</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="bp">False</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">f</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<span class="go">['def', 123, False]</span>
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.2.</span></p>
</div>
</dd></dl>
<dl class="method">
<dt id="pykka.Future.map">
<code class="descname">map</code><span class="sig-paren">(</span><em>func</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/future.html#Future.map"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.Future.map" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a new future with the result of the future passed through a
function.</p>
<p>If the future’s result is a single value, it is simply passed to the
function. If the future’s result is an iterable, the function is
applied to each item in the iterable.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">pykka</span>
<span class="gp">>>> </span><span class="n">f</span> <span class="o">=</span> <span class="n">pykka</span><span class="o">.</span><span class="n">ThreadingFuture</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">g</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">10</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">f</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="mi">30</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<span class="go">40</span>
<span class="gp">>>> </span><span class="n">f</span> <span class="o">=</span> <span class="n">pykka</span><span class="o">.</span><span class="n">ThreadingFuture</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">g</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span> <span class="o">+</span> <span class="mi">10</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">f</span><span class="o">.</span><span class="n">set</span><span class="p">([</span><span class="mi">30</span><span class="p">,</span> <span class="mi">300</span><span class="p">,</span> <span class="mi">3000</span><span class="p">])</span>
<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<span class="go">[40, 310, 3010]</span>
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.2.</span></p>
</div>
</dd></dl>
<dl class="method">
<dt id="pykka.Future.reduce">
<code class="descname">reduce</code><span class="sig-paren">(</span><em>func</em><span class="optional">[</span>, <em>initial</em><span class="optional">]</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/future.html#Future.reduce"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.Future.reduce" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a new future with the result of reducing the future’s iterable
into a single value.</p>
<p>The function of two arguments is applied cumulatively to the items of
the iterable, from left to right. The result of the first function call
is used as the first argument to the second function call, and so on,
until the end of the iterable. If the future’s value isn’t an iterable,
a <code class="xref py py-exc docutils literal"><span class="pre">TypeError</span></code> is raised.</p>
<p><a class="reference internal" href="#pykka.Future.reduce" title="pykka.Future.reduce"><code class="xref py py-meth docutils literal"><span class="pre">reduce()</span></code></a> accepts an optional second argument, which will be used
as an initial value in the first function call. If the iterable is
empty, the initial value is returned.</p>
<p>Example:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">pykka</span>
<span class="gp">>>> </span><span class="n">f</span> <span class="o">=</span> <span class="n">pykka</span><span class="o">.</span><span class="n">ThreadingFuture</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">g</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">reduce</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">f</span><span class="o">.</span><span class="n">set</span><span class="p">([</span><span class="s">'a'</span><span class="p">,</span> <span class="s">'b'</span><span class="p">,</span> <span class="s">'c'</span><span class="p">])</span>
<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<span class="go">'abc'</span>
<span class="gp">>>> </span><span class="n">f</span> <span class="o">=</span> <span class="n">pykka</span><span class="o">.</span><span class="n">ThreadingFuture</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">g</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">reduce</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">f</span><span class="o">.</span><span class="n">set</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="gp">>>> </span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="mi">3</span>
<span class="go">6</span>
<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<span class="go">6</span>
<span class="gp">>>> </span><span class="n">f</span> <span class="o">=</span> <span class="n">pykka</span><span class="o">.</span><span class="n">ThreadingFuture</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">g</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">reduce</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">f</span><span class="o">.</span><span class="n">set</span><span class="p">([</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">])</span>
<span class="gp">>>> </span><span class="p">((</span><span class="mi">5</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="mi">3</span>
<span class="go">11</span>
<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<span class="go">11</span>
<span class="gp">>>> </span><span class="n">f</span> <span class="o">=</span> <span class="n">pykka</span><span class="o">.</span><span class="n">ThreadingFuture</span><span class="p">()</span>
<span class="gp">>>> </span><span class="n">g</span> <span class="o">=</span> <span class="n">f</span><span class="o">.</span><span class="n">reduce</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">:</span> <span class="n">x</span> <span class="o">+</span> <span class="n">y</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">f</span><span class="o">.</span><span class="n">set</span><span class="p">([])</span>
<span class="gp">>>> </span><span class="n">g</span><span class="o">.</span><span class="n">get</span><span class="p">()</span>
<span class="go">5</span>
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.2.</span></p>
</div>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="pykka.ThreadingFuture">
<em class="property">class </em><code class="descclassname">pykka.</code><code class="descname">ThreadingFuture</code><a class="reference internal" href="_modules/pykka/threading.html#ThreadingFuture"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.ThreadingFuture" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#pykka.ThreadingFuture" title="pykka.ThreadingFuture"><code class="xref py py-class docutils literal"><span class="pre">ThreadingFuture</span></code></a> implements <a class="reference internal" href="#pykka.Future" title="pykka.Future"><code class="xref py py-class docutils literal"><span class="pre">Future</span></code></a> for use with
<a class="reference internal" href="#pykka.ThreadingActor" title="pykka.ThreadingActor"><code class="xref py py-class docutils literal"><span class="pre">ThreadingActor</span></code></a>.</p>
<p>The future is implemented using a <code class="xref py py-class docutils literal"><span class="pre">Queue.Queue</span></code>.</p>
<p>The future does <em>not</em> make a copy of the object which is <a class="reference internal" href="#pykka.Future.set" title="pykka.Future.set"><code class="xref py py-meth docutils literal"><span class="pre">set()</span></code></a> on it. It is the setters responsibility to only pass
immutable objects or make a copy of the object before setting it on the
future.</p>
<div class="versionchanged">
<p><span class="versionmodified">Changed in version 0.14: </span>Previously, the encapsulated value was a copy made with
<code class="xref py py-func docutils literal"><span class="pre">copy.deepcopy()</span></code>, unless the encapsulated value was a future, in
which case the original future was encapsulated.</p>
</div>
</dd></dl>
<dl class="function">
<dt id="pykka.get_all">
<code class="descclassname">pykka.</code><code class="descname">get_all</code><span class="sig-paren">(</span><em>futures</em>, <em>timeout=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/future.html#get_all"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.get_all" title="Permalink to this definition">¶</a></dt>
<dd><p>Collect all values encapsulated in the list of futures.</p>
<p>If <code class="docutils literal"><span class="pre">timeout</span></code> is not <code class="xref py py-class docutils literal"><span class="pre">None</span></code>, the method will wait for a reply for
<code class="docutils literal"><span class="pre">timeout</span></code> seconds, and then raise <a class="reference internal" href="#pykka.Timeout" title="pykka.Timeout"><code class="xref py py-exc docutils literal"><span class="pre">pykka.Timeout</span></code></a>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>futures</strong> (list of <a class="reference internal" href="#pykka.Future" title="pykka.Future"><code class="xref py py-class docutils literal"><span class="pre">pykka.Future</span></code></a>) – futures for the results to collect</li>
<li><strong>timeout</strong> (float or <code class="xref py py-class docutils literal"><span class="pre">None</span></code>) – seconds to wait before timeout</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Raise:</th><td class="field-body"><p class="first"><a class="reference internal" href="#pykka.Timeout" title="pykka.Timeout"><code class="xref py py-exc docutils literal"><span class="pre">pykka.Timeout</span></code></a> if timeout is reached</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><p class="first last">list of results</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>
</div>
<div class="section" id="registry">
<h2>Registry<a class="headerlink" href="#registry" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="pykka.ActorRegistry">
<em class="property">class </em><code class="descclassname">pykka.</code><code class="descname">ActorRegistry</code><a class="reference internal" href="_modules/pykka/registry.html#ActorRegistry"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.ActorRegistry" title="Permalink to this definition">¶</a></dt>
<dd><p>Registry which provides easy access to all running actors.</p>
<p>Contains global state, but should be thread-safe.</p>
<dl class="classmethod">
<dt id="pykka.ActorRegistry.broadcast">
<em class="property">classmethod </em><code class="descname">broadcast</code><span class="sig-paren">(</span><em>message</em>, <em>target_class=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/registry.html#ActorRegistry.broadcast"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.ActorRegistry.broadcast" title="Permalink to this definition">¶</a></dt>
<dd><p>Broadcast <code class="docutils literal"><span class="pre">message</span></code> to all actors of the specified <code class="docutils literal"><span class="pre">target_class</span></code>.</p>
<p>If no <code class="docutils literal"><span class="pre">target_class</span></code> is specified, the message is broadcasted to all
actors.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><strong>message</strong> (<em>picklable dict</em>) – the message to send</li>
<li><strong>target_class</strong> (<em>class or class name</em>) – optional actor class to broadcast the message to</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="classmethod">
<dt id="pykka.ActorRegistry.get_all">
<em class="property">classmethod </em><code class="descname">get_all</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/registry.html#ActorRegistry.get_all"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.ActorRegistry.get_all" title="Permalink to this definition">¶</a></dt>
<dd><p>Get <a class="reference internal" href="#pykka.ActorRef" title="pykka.ActorRef"><code class="xref py py-class docutils literal"><span class="pre">ActorRef</span></code></a> for all running actors.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">list of <a class="reference internal" href="#pykka.ActorRef" title="pykka.ActorRef"><code class="xref py py-class docutils literal"><span class="pre">pykka.ActorRef</span></code></a></td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="classmethod">
<dt id="pykka.ActorRegistry.get_by_class">
<em class="property">classmethod </em><code class="descname">get_by_class</code><span class="sig-paren">(</span><em>actor_class</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/registry.html#ActorRegistry.get_by_class"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.ActorRegistry.get_by_class" title="Permalink to this definition">¶</a></dt>
<dd><p>Get <a class="reference internal" href="#pykka.ActorRef" title="pykka.ActorRef"><code class="xref py py-class docutils literal"><span class="pre">ActorRef</span></code></a> for all running actors of the given class, or of
any subclass of the given class.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>actor_class</strong> (<em>class</em>) – actor class, or any superclass of the actor</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">list of <a class="reference internal" href="#pykka.ActorRef" title="pykka.ActorRef"><code class="xref py py-class docutils literal"><span class="pre">pykka.ActorRef</span></code></a></td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="classmethod">
<dt id="pykka.ActorRegistry.get_by_class_name">
<em class="property">classmethod </em><code class="descname">get_by_class_name</code><span class="sig-paren">(</span><em>actor_class_name</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/registry.html#ActorRegistry.get_by_class_name"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.ActorRegistry.get_by_class_name" title="Permalink to this definition">¶</a></dt>
<dd><p>Get <a class="reference internal" href="#pykka.ActorRef" title="pykka.ActorRef"><code class="xref py py-class docutils literal"><span class="pre">ActorRef</span></code></a> for all running actors of the given class
name.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>actor_class_name</strong> (<em>string</em>) – actor class name</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">list of <a class="reference internal" href="#pykka.ActorRef" title="pykka.ActorRef"><code class="xref py py-class docutils literal"><span class="pre">pykka.ActorRef</span></code></a></td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="classmethod">
<dt id="pykka.ActorRegistry.get_by_urn">
<em class="property">classmethod </em><code class="descname">get_by_urn</code><span class="sig-paren">(</span><em>actor_urn</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/registry.html#ActorRegistry.get_by_urn"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.ActorRegistry.get_by_urn" title="Permalink to this definition">¶</a></dt>
<dd><p>Get an actor by its universally unique URN.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>actor_urn</strong> (<em>string</em>) – actor URN</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><a class="reference internal" href="#pykka.ActorRef" title="pykka.ActorRef"><code class="xref py py-class docutils literal"><span class="pre">pykka.ActorRef</span></code></a> or <code class="xref py py-class docutils literal"><span class="pre">None</span></code> if not found</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="classmethod">
<dt id="pykka.ActorRegistry.register">
<em class="property">classmethod </em><code class="descname">register</code><span class="sig-paren">(</span><em>actor_ref</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/registry.html#ActorRegistry.register"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.ActorRegistry.register" title="Permalink to this definition">¶</a></dt>
<dd><p>Register an <a class="reference internal" href="#pykka.ActorRef" title="pykka.ActorRef"><code class="xref py py-class docutils literal"><span class="pre">ActorRef</span></code></a> in the registry.</p>
<p>This is done automatically when an actor is started, e.g. by calling
<a class="reference internal" href="#pykka.Actor.start" title="pykka.Actor.start"><code class="xref py py-meth docutils literal"><span class="pre">Actor.start()</span></code></a>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>actor_ref</strong> (<a class="reference internal" href="#pykka.ActorRef" title="pykka.ActorRef"><code class="xref py py-class docutils literal"><span class="pre">pykka.ActorRef</span></code></a>) – reference to the actor to register</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="classmethod">
<dt id="pykka.ActorRegistry.stop_all">
<em class="property">classmethod </em><code class="descname">stop_all</code><span class="sig-paren">(</span><em>block=True</em>, <em>timeout=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/registry.html#ActorRegistry.stop_all"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.ActorRegistry.stop_all" title="Permalink to this definition">¶</a></dt>
<dd><p>Stop all running actors.</p>
<p><code class="docutils literal"><span class="pre">block</span></code> and <code class="docutils literal"><span class="pre">timeout</span></code> works as for
<a class="reference internal" href="#pykka.ActorRef.stop" title="pykka.ActorRef.stop"><code class="xref py py-meth docutils literal"><span class="pre">ActorRef.stop()</span></code></a>.</p>
<p>If <code class="docutils literal"><span class="pre">block</span></code> is <code class="xref py py-class docutils literal"><span class="pre">True</span></code>, the actors are guaranteed to be stopped
in the reverse of the order they were started in. This is helpful if
you have simple dependencies in between your actors, where it is
sufficient to shut down actors in a LIFO manner: last started, first
stopped.</p>
<p>If you have more complex dependencies in between your actors, you
should take care to shut them down in the required order yourself, e.g.
by stopping dependees from a dependency’s
<a class="reference internal" href="#pykka.Actor.on_stop" title="pykka.Actor.on_stop"><code class="xref py py-meth docutils literal"><span class="pre">on_stop()</span></code></a> method.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">If not blocking, a list with a future for each stop action.
If blocking, a list of return values from
<a class="reference internal" href="#pykka.ActorRef.stop" title="pykka.ActorRef.stop"><code class="xref py py-meth docutils literal"><span class="pre">pykka.ActorRef.stop()</span></code></a>.</td>
</tr>
</tbody>
</table>
</dd></dl>
<dl class="classmethod">
<dt id="pykka.ActorRegistry.unregister">
<em class="property">classmethod </em><code class="descname">unregister</code><span class="sig-paren">(</span><em>actor_ref</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/registry.html#ActorRegistry.unregister"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.ActorRegistry.unregister" title="Permalink to this definition">¶</a></dt>
<dd><p>Remove an <a class="reference internal" href="#pykka.ActorRef" title="pykka.ActorRef"><code class="xref py py-class docutils literal"><span class="pre">ActorRef</span></code></a> from the registry.</p>
<p>This is done automatically when an actor is stopped, e.g. by calling
<a class="reference internal" href="#pykka.Actor.stop" title="pykka.Actor.stop"><code class="xref py py-meth docutils literal"><span class="pre">Actor.stop()</span></code></a>.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>actor_ref</strong> (<a class="reference internal" href="#pykka.ActorRef" title="pykka.ActorRef"><code class="xref py py-class docutils literal"><span class="pre">pykka.ActorRef</span></code></a>) – reference to the actor to unregister</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
</div>
<div class="section" id="module-pykka.gevent">
<span id="gevent-support"></span><h2>Gevent support<a class="headerlink" href="#module-pykka.gevent" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="pykka.gevent.GeventFuture">
<em class="property">class </em><code class="descclassname">pykka.gevent.</code><code class="descname">GeventFuture</code><span class="sig-paren">(</span><em>async_result=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/gevent.html#GeventFuture"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.gevent.GeventFuture" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#pykka.gevent.GeventFuture" title="pykka.gevent.GeventFuture"><code class="xref py py-class docutils literal"><span class="pre">GeventFuture</span></code></a> implements <a class="reference internal" href="#pykka.Future" title="pykka.Future"><code class="xref py py-class docutils literal"><span class="pre">pykka.Future</span></code></a> for use with
<a class="reference internal" href="#pykka.gevent.GeventActor" title="pykka.gevent.GeventActor"><code class="xref py py-class docutils literal"><span class="pre">GeventActor</span></code></a>.</p>
<p>It encapsulates a <code class="xref py py-class docutils literal"><span class="pre">gevent.event.AsyncResult</span></code> object which may be
used directly, though it will couple your code with gevent.</p>
<dl class="attribute">
<dt id="pykka.gevent.GeventFuture.async_result">
<code class="descname">async_result</code><em class="property"> = None</em><a class="headerlink" href="#pykka.gevent.GeventFuture.async_result" title="Permalink to this definition">¶</a></dt>
<dd><p>The encapsulated <code class="xref py py-class docutils literal"><span class="pre">gevent.event.AsyncResult</span></code></p>
</dd></dl>
</dd></dl>
<dl class="class">
<dt id="pykka.gevent.GeventActor">
<em class="property">class </em><code class="descclassname">pykka.gevent.</code><code class="descname">GeventActor</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/gevent.html#GeventActor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.gevent.GeventActor" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#pykka.gevent.GeventActor" title="pykka.gevent.GeventActor"><code class="xref py py-class docutils literal"><span class="pre">GeventActor</span></code></a> implements <a class="reference internal" href="#pykka.Actor" title="pykka.Actor"><code class="xref py py-class docutils literal"><span class="pre">pykka.Actor</span></code></a> using the <a class="reference external" href="http://www.gevent.org/">gevent</a> library. gevent is a coroutine-based Python
networking library that uses greenlet to provide a high-level synchronous
API on top of libevent event loop.</p>
<p>This is a very fast implementation, but as of gevent 0.13.x it does not
work in combination with other threads.</p>
</dd></dl>
</div>
<div class="section" id="module-pykka.eventlet">
<span id="eventlet-support"></span><h2>Eventlet support<a class="headerlink" href="#module-pykka.eventlet" title="Permalink to this headline">¶</a></h2>
<dl class="class">
<dt id="pykka.eventlet.EventletEvent">
<em class="property">class </em><code class="descclassname">pykka.eventlet.</code><code class="descname">EventletEvent</code><a class="reference internal" href="_modules/pykka/eventlet.html#EventletEvent"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.eventlet.EventletEvent" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#pykka.eventlet.EventletEvent" title="pykka.eventlet.EventletEvent"><code class="xref py py-class docutils literal"><span class="pre">EventletEvent</span></code></a> adapts <code class="xref py py-class docutils literal"><span class="pre">eventlet.event.Event</span></code> to
<code class="xref py py-class docutils literal"><span class="pre">threading.Event</span></code> interface.</p>
</dd></dl>
<dl class="class">
<dt id="pykka.eventlet.EventletFuture">
<em class="property">class </em><code class="descclassname">pykka.eventlet.</code><code class="descname">EventletFuture</code><a class="reference internal" href="_modules/pykka/eventlet.html#EventletFuture"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.eventlet.EventletFuture" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#pykka.eventlet.EventletFuture" title="pykka.eventlet.EventletFuture"><code class="xref py py-class docutils literal"><span class="pre">EventletFuture</span></code></a> implements <a class="reference internal" href="#pykka.Future" title="pykka.Future"><code class="xref py py-class docutils literal"><span class="pre">pykka.Future</span></code></a> for use with
<a class="reference internal" href="#pykka.eventlet.EventletActor" title="pykka.eventlet.EventletActor"><code class="xref py py-class docutils literal"><span class="pre">EventletActor</span></code></a>.</p>
</dd></dl>
<dl class="class">
<dt id="pykka.eventlet.EventletActor">
<em class="property">class </em><code class="descclassname">pykka.eventlet.</code><code class="descname">EventletActor</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/eventlet.html#EventletActor"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.eventlet.EventletActor" title="Permalink to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#pykka.eventlet.EventletActor" title="pykka.eventlet.EventletActor"><code class="xref py py-class docutils literal"><span class="pre">EventletActor</span></code></a> implements <a class="reference internal" href="#pykka.Actor" title="pykka.Actor"><code class="xref py py-class docutils literal"><span class="pre">pykka.Actor</span></code></a> using the <a class="reference external" href="http://eventlet.net/">eventlet</a> library.</p>
<p>This implementation uses eventlet green threads.</p>
</dd></dl>
</div>
<div class="section" id="logging">
<h2>Logging<a class="headerlink" href="#logging" title="Permalink to this headline">¶</a></h2>
<p>Pykka uses Python’s standard <code class="xref py py-mod docutils literal"><span class="pre">logging</span></code> module for logging debug statements
and any unhandled exceptions in the actors. All log records emitted by Pykka
are issued to the logger named “pykka”, or a sublogger of it.</p>
<p>Out of the box, Pykka is set up with <code class="xref py py-class docutils literal"><span class="pre">logging.NullHandler</span></code> as the only
log record handler. This is the recommended approach for logging in
libraries, so that the application developer using the library will have full
control over how the log records from the library will be exposed to the
application’s users. In other words, if you want to see the log records from
Pykka anywhere, you need to add a useful handler to the root logger or the
logger named “pykka” to get any log output from Pykka. The defaults provided by
<code class="xref py py-meth docutils literal"><span class="pre">logging.basicConfig()</span></code> is enough to get debug log statements out of
Pykka:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">logging</span>
<span class="n">logging</span><span class="o">.</span><span class="n">basicConfig</span><span class="p">(</span><span class="n">level</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">)</span>
</pre></div>
</div>
<p>If your application is already using <code class="xref py py-mod docutils literal"><span class="pre">logging</span></code>, and you want debug log
output from your own application, but not from Pykka, you can ignore debug log
messages from Pykka by increasing the threshold on the Pykka logger to “info”
level or higher:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">logging</span>
<span class="n">logging</span><span class="o">.</span><span class="n">basicConfig</span><span class="p">(</span><span class="n">level</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">)</span>
<span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s">'pykka'</span><span class="p">)</span><span class="o">.</span><span class="n">setLevel</span><span class="p">(</span><span class="n">logging</span><span class="o">.</span><span class="n">INFO</span><span class="p">)</span>
</pre></div>
</div>
<p>For more details on how to use <code class="xref py py-mod docutils literal"><span class="pre">logging</span></code>, please refer to the Python
standard library documentation.</p>
</div>
<div class="section" id="module-pykka.debug">
<span id="debug-helpers"></span><h2>Debug helpers<a class="headerlink" href="#module-pykka.debug" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="pykka.debug.log_thread_tracebacks">
<code class="descclassname">pykka.debug.</code><code class="descname">log_thread_tracebacks</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/pykka/debug.html#log_thread_tracebacks"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pykka.debug.log_thread_tracebacks" title="Permalink to this definition">¶</a></dt>
<dd><p>Logs at <code class="docutils literal"><span class="pre">CRITICAL</span></code> level a traceback for each running thread.</p>
<p>This can be a convenient tool for debugging deadlocks.</p>
<p>The function accepts any arguments so that it can easily be used as e.g. a
signal handler, but it does not use the arguments for anything.</p>
<p>To use this function as a signal handler, setup logging with a
<code class="xref py py-attr docutils literal"><span class="pre">logging.CRITICAL</span></code> threshold or lower and make your main thread
register this with the <code class="xref py py-mod docutils literal"><span class="pre">signal</span></code> module:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">signal</span>
<span class="kn">import</span> <span class="nn">pykka.debug</span>
<span class="n">logging</span><span class="o">.</span><span class="n">basicConfig</span><span class="p">(</span><span class="n">level</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">)</span>
<span class="n">signal</span><span class="o">.</span><span class="n">signal</span><span class="p">(</span><span class="n">signal</span><span class="o">.</span><span class="n">SIGUSR1</span><span class="p">,</span> <span class="n">pykka</span><span class="o">.</span><span class="n">debug</span><span class="o">.</span><span class="n">log_thread_tracebacks</span><span class="p">)</span>
</pre></div>
</div>
<p>If your application deadlocks, send the <cite>SIGUSR1</cite> signal to the process:</p>
<div class="highlight-python"><div class="highlight"><pre>kill -SIGUSR1 <pid of your process>
</pre></div>
</div>
<p>Signal handler caveats:</p>
<ul class="simple">
<li>The function <em>must</em> be registered as a signal handler by your main
thread. If not, <code class="xref py py-func docutils literal"><span class="pre">signal.signal()</span></code> will raise a <code class="xref py py-exc docutils literal"><span class="pre">ValueError</span></code>.</li>
<li>All signals in Python are handled by the main thread. Thus, the signal
will only be handled, and the tracebacks logged, if your main thread is
available to do some work. Making your main thread idle using
<code class="xref py py-func docutils literal"><span class="pre">time.sleep()</span></code> is OK. The signal will awaken your main thread.
Blocking your main thread on e.g. <code class="xref py py-func docutils literal"><span class="pre">Queue.Queue.get()</span></code> or
<a class="reference internal" href="#pykka.Future.get" title="pykka.Future.get"><code class="xref py py-meth docutils literal"><span class="pre">pykka.Future.get()</span></code></a> will break signal handling, and thus you won’t
be able to signal your process to print the thread tracebacks.</li>
</ul>
<p>The morale is: setup signals using your main thread, start your actors,
then let your main thread relax for the rest of your application’s life
cycle.</p>
<p>For a complete example of how to use this, see
<code class="docutils literal"><span class="pre">examples/deadlock_debugging.py</span></code> in Pykka’s source code.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 1.1.</span></p>
</div>
</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="#">Pykka API</a><ul>
<li><a class="reference internal" href="#actors">Actors</a></li>
<li><a class="reference internal" href="#proxies">Proxies</a></li>
<li><a class="reference internal" href="#futures">Futures</a></li>
<li><a class="reference internal" href="#registry">Registry</a></li>
<li><a class="reference internal" href="#module-pykka.gevent">Gevent support</a></li>
<li><a class="reference internal" href="#module-pykka.eventlet">Eventlet support</a></li>
<li><a class="reference internal" href="#logging">Logging</a></li>
<li><a class="reference internal" href="#module-pykka.debug">Debug helpers</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="index.html"
title="previous chapter">Pykka</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="changes.html"
title="next chapter">Changes</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="_sources/api.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">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
<p class="searchtip" style="font-size: 90%">
Enter search terms or a module, class or function name.
</p>
</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="changes.html" title="Changes"
>next</a> |</li>
<li class="right" >
<a href="index.html" title="Pykka"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="index.html">Pykka 1.2.1 documentation</a> »</li>
</ul>
</div>
<div class="footer" role="contentinfo">
© Copyright 2010-2015, Stein Magnus Jodal.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.3.1.
</div>
</body>
</html>
|