Package grassyknoll :: Package concurrent :: Module Worker :: Class Worker
[hide private]

Class Worker

source code


a worker threading.Thread with MailBox.MailBox support


Note: Using ThreadPool is preferred, even with only a single worker.

Instance Methods [hide private]
 
__init__(self, inbox, context_factory, name=None, verbose=None, daemon=False, unhandled="die") source code
tuple
checkMessages(self)
check for new Messages for this worker
source code
 
run(self)
do the work; do not call directly - try start() instead
source code
Message
doExits(self, mesg)
handle WorkerExit and ContextExit.
source code
Message
callFunc(self, func, mesg)
Call the current func with a mesg.
source code
 
sendReply(self, mesg, reply)
send a reply to mesg.
source code

Inherited from threading.Thread: __repr__, getName, isAlive, isDaemon, join, setDaemon, setName, start

Inherited from threading.Thread (private): _set_daemon

Inherited from threading._Verbose (private): _note

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __str__

Class Variables [hide private]
  logger = AutoLogger()
Instance Variables [hide private]
context manager context
the in-use context.
  context_factory
factory returning a context manager.
MailBox.MailBox inbox
shared source of Messages
bool newcontext
should new contexts be created? When False, the thread exits.
string unhandled
one of die, newcontext, keeprunning, indicating how uncaught exceptions should be handled.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, inbox, context_factory, name=None, verbose=None, daemon=False, unhandled="die")
(Constructor)

source code 
Parameters:
  • context_factory - factory
Overrides: threading.Thread.__init__

checkMessages(self)

source code 
check for new Messages for this worker
Returns: tuple
a Message and the the MailBox.MailBox it came from.

run(self)

source code 
do the work; do not call directly - try start() instead
Overrides: threading.Thread.run

doExits(self, mesg)

source code 
handle WorkerExit and ContextExit. For internal use.
Parameters:
Returns: Message
a Message with True as a payload

callFunc(self, func, mesg)

source code 
Call the current func with a mesg. For internal use.
Parameters:
  • mesg (Message) - the current Message
  • func (callable) - the function from the current context, that returns a Message
Returns: Message
the Message returned by func. In the event of an unhandled exception, may return a message with a CrashError as a payload. See unhandled.

sendReply(self, mesg, reply)

source code 
send a reply to mesg. For internal use.
Parameters:

Instance Variable Details [hide private]

context

the in-use context. For internal use/debugging.
Type:
context manager

context_factory

factory returning a context manager. See module docs.

newcontext

should new contexts be created? When False, the thread exits. For internal use.
Type:
bool