Skip to content

Generators in Actor method #215

Answered by jodal
callmephilip asked this question in Q&A
Discussion options

You must be logged in to vote

If one wanted to implement the actor pattern in the safest way possible, the actor would serialize its messages to e.g. the pickle format or JSON before sending it. For performance reasons, Pykka does not do that, and leaves it to use as the user to only return objects that can safely be shared between threads.

Your example works because you simply return a generator object, and the caller can then iterate of the generator. On the surface, this seems to work. I think the big question is, where does the generator work happen? In the actor, or on the main thread?

If we change the example briefly:

import threading
from typing import Iterable

import pykka

class PlainActor(pykka.ThreadingActor

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by callmephilip
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants