jodal/pykka — pull request #23 by jstasiak (2013-05-30 21:07:21+00:00)
Title: Handle messages left in actor inbox after it's stopped

This patch implements responding with ``ActorDeadError`` to the messages that are present in actor inbox after it's stopped (or, in case of ``pykka_stop`` message(s), just completing the future).

This patch also fixes an issue, already present in Pykka, that made ``ThreadingActor.test_actor_can_call_stop_on_self_multiple_times`` test to fail every now and then (https://travis-ci.org/jodal/pykka/jobs/7517791).

The issue was caused by multiple ``pykka_stop`` messages finding their way to an actor inbox, first one stopping the actor and the rest of them stuck in the queue forever. Therefore sometimes ``ActorRegistry.stop_all``, which is called from teardown method, just waited indefinitely for the response from ``pykka_stop`` handler. (to be able to reproduce that more reliably I just added ``sleep(1)`` at the beginning of ``Actor._stop()``).

This bug was affecting threading actor as well as gevent and Eventlet actors, however I believe the use of real threads and blocking main thread on ``stop_all()`` call is what caused this issue to be visible in ``ThreadingActor`` test only.

Note: this pull depends on #22 therefore one of the commits from this pull request is the commit already submitted there.