pynetdicom.transport.ThreadedAssociationServer¶
-
class
pynetdicom.transport.ThreadedAssociationServer(ae, address, ae_title, contexts, ssl_context=None, evt_handlers=None)[source]¶ An
AssociationServersuitable for threading.-
__init__(ae, address, ae_title, contexts, ssl_context=None, evt_handlers=None)[source]¶ Create a new AssociationServer, bind a socket and start listening.
- Parameters
ae (ae.ApplicationEntity) – The parent AE that’s running the server.
address (2-tuple) – The
(host, port)that the server should run on.ae_title (bytes) – The AE title of the SCP.
contexts (list of presentation.PresentationContext) – The SCPs supported presentation contexts.
ssl_context (ssl.SSLContext, optional) – If TLS is to be used then this should be the
ssl.SSLContextused to wrap the client sockets, otherwise ifNonethen no TLS will beused (default).evt_handlers (list of 2-tuple, optional) – A list of
(event, callable), the callable function to run when event occurs.
Methods
__init__(ae, address, ae_title, contexts[, …])Create a new AssociationServer, bind a socket and start listening.
bind(event, handler)Bind a callable handler to an event.
close_request(request)Called to clean up an individual request.
fileno()Return socket file number.
finish_request(request, client_address)Finish one request by instantiating RequestHandlerClass.
Return a list of currently bound events.
get_handlers(event)Return handlers bound to a specific event.
Handle a connection request.
handle_error(request, client_address)Handle an error gracefully.
Handle one request, possibly blocking.
Called if no new request arrives within self.timeout.
process_request(request, client_address)Start a new thread to process the request.
process_request_thread(request, client_address)Process a connection request.
serve_forever([poll_interval])Handle one request at a time until shutdown.
Called by constructor to activate the server.
Bind the socket and set the socket options.
server_close()Called by the serve_forever() loop.
shutdown()Completely shutdown the server and close it’s socket.
shutdown_request(request)Called to shutdown and close an individual request.
unbind(event, handler)Unbind a callable handler from an event.
verify_request(request, client_address)Verify the request.
Attributes
Return the server’s running
Associationacceptor instancesaddress_familyallow_reuse_addressdaemon_threadsrequest_queue_sizesocket_typetimeout-
property
active_associations¶ Return the server’s running
Associationacceptor instances
-
bind(event, handler)[source]¶ Bind a callable handler to an event.
- Parameters
event (3-tuple) – The event to bind the function to.
handler (callable) – The function that will be called if the event occurs.
-
finish_request(request, client_address)[source]¶ Finish one request by instantiating RequestHandlerClass.
-
get_handlers(event)[source]¶ Return handlers bound to a specific event.
- Parameters
event (tuple) – The event bound to the handlers.
- Returns
If the event is a notification event then returns a list of callable functions bound to
event, if the event is an intervention event then returns either a callable function if a handler is bound to the event orNoneif no handler has been bound.- Return type
callable, list of callable or None
-
get_request()[source]¶ Handle a connection request.
If
ssl_contextis set then the client socket will be wrapped usingssl_context.wrap_socket().- Returns
client_socket (socket._socket) – The connection request.
address (2-tuple) – The client’s address as
(host, port).
-
handle_error(request, client_address)[source]¶ Handle an error gracefully. May be overridden.
The default is to print a traceback and continue.
-
handle_timeout()[source]¶ Called if no new request arrives within self.timeout.
Overridden by ForkingMixIn.
-
serve_forever(poll_interval=0.5)[source]¶ Handle one request at a time until shutdown.
Polls for shutdown every poll_interval seconds. Ignores self.timeout. If you need to do periodic tasks, do them in another thread.
-
server_bind()[source]¶ Bind the socket and set the socket options.
socket.SO_REUSEADDRis set to 1socket.SO_RCVTIMEOis set toAE.network_timeoutunless the value isNonein which case it will be left unset.
-
service_actions()[source]¶ Called by the serve_forever() loop.
May be overridden by a subclass / Mixin to implement any code that needs to be run during the loop.
-