Threaded networking base classes

Threaded networking facilities for implementing threaded WS-Discovery daemons.

class wsdiscovery.threaded.AddressMonitorThread(wsd)

trigger address change callbacks when local service addresses change

_updateAddrs()
run()

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

class wsdiscovery.threaded.NetworkingThread(observer, capture=None)
static _createMulticastInSocket()
static _createMulticastOutSocket(addr, ttl)
static _makeMreq(addr)
_recvMessages()
_sendMsg(msg)
_sendPendingMessages()

Method sleeps, if nothing to do

addMulticastMessage(env, addr, port, initialDelay=0)
addSourceAddr(addr)

None means ‘system default’

addUnicastMessage(env, addr, port, initialDelay=0)
join()

Wait until the thread terminates.

This blocks the calling thread until the thread whose join() method is called terminates – either normally or through an unhandled exception or until the optional timeout occurs.

When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof). As join() always returns None, you must call is_alive() after join() to decide whether a timeout happened – if the thread is still alive, the join() call timed out.

When the timeout argument is not present or None, the operation will block until the thread terminates.

A thread can be join()ed many times.

join() raises a RuntimeError if an attempt is made to join the current thread as that would cause a deadlock. It is also an error to join() a thread before it has been started and attempts to do so raises the same exception.

removeSourceAddr(addr)
run()

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

start()

Start the thread’s activity.

It must be called at most once per thread object. It arranges for the object’s run() method to be invoked in a separate thread of control.

This method will raise a RuntimeError if called more than once on the same thread object.

class wsdiscovery.threaded.ThreadedNetworking(**kwargs)

handle threaded networking start & stop, address add/remove & message sending

_startThreads()
_stopThreads()
addSourceAddr(addr)
removeSourceAddr(addr)
sendMulticastMessage(env, initialDelay=0)

handle multicast message sending

sendUnicastMessage(env, host, port, initialDelay=0)

handle unicast message sending

start()

start networking - should be called before using other methods

stop()

cleans up and stops networking

class wsdiscovery.threaded._StoppableDaemonThread

Stoppable daemon thread.

run() method shall exit, when self._quitEvent.wait() returned True

schedule_stop()

Schedule stopping the thread. Use join() to wait, until thread really has been stopped