Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support daemon threads. #14

Closed
acertain opened this issue Jan 8, 2013 · 4 comments
Closed

Support daemon threads. #14

acertain opened this issue Jan 8, 2013 · 4 comments
Assignees

Comments

@acertain
Copy link

acertain commented Jan 8, 2013

Daemon threads stop when all non-daemon threads have stopped: http://docs.python.org/2/library/threading.html#threading.Thread.daemon It would be nice to be able to mark actors as daemon.

@jodal
Copy link
Owner

jodal commented Jan 8, 2013

To better understand the use case:

  1. Is this something you want for a few or all actors?
  2. If you only want it for a few actors, what kind of tasks are those actors typically doing? What's the difference between them and the non-daemon actors?
  3. Are you okay with on_stop() being called when a single "daemon" actor is stopped, but on_stop() not being called when the actor shuts down because all non-daemon threads are done?
  4. What kind of workarounds, if any, are you currently using?

@acertain
Copy link
Author

acertain commented Jan 8, 2013

On Tue, Jan 8, 2013 at 2:29 AM, Stein Magnus Jodal <notifications@github.com

wrote:
To better understand the use case:

  1. Is this something you want for a few or all actors?
    All actors, because I am only using a few.
  2. If you only want it for a few actors, what kind of tasks are those
    actors typically doing? What's the difference between them and the
    non-daemon actors?
    Tasks like logging with SMTP.
  3. Are you okay with on_stop() being called when a single "daemon" actor
    is stopped, but on_stop() not being called when the actor shuts down
    because all non-daemon threads are done?
    I think so.
  4. What kind of workarounds, if any, are you currently using?
    Calling my program in a separate file with

try:
from app import app
app.main()
finally:
import pykka
pykka.ActorRegistry.stop_all()

@jodal jodal closed this as completed in f5c1841 Jan 12, 2013
@jodal
Copy link
Owner

jodal commented Jan 12, 2013

I just added support for using daemon threads. Could you give it a spin and see if it works for you before I release v1.1?

You can install the development version either by installing from the git repo or running pip install pykka==dev.

@ghost ghost assigned jodal Jan 12, 2013
@jodal
Copy link
Owner

jodal commented Jan 12, 2013

I might add that to make a ThreadingActor use a daemon thread, you should set the self.use_daemon_thread = True on the actor before start() is called. Example:

class AnActor(pykka.ThreadingActor):
    use_daemon_thread = True
    ...

AnActor.start()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants