multithreading - python socketserver: how to shutdown server with open client connection? -


i have been looking time solution terminate socketserver.streamrequesthandler spawned separate thread class threadingmixin when main tread terminates. problem socketserver thread, although being daemonic, not terminate long there open client connection, when calling shutdown() method @ program shutdown. therefore, main tread did not terminate. none of suggestions in how stop basehttpserver.serve_forever() in basehttprequesthandler subclass? or similar posts worked me.

i have found solution: class threadingmixin has property daemonic_threads, default true:

class threadingmixin: """mix-in class handle each request in new thread.""" # decides how threads act upon termination of # main process daemon_threads = false 

in subclass, which, of course, overrides method handle(), defines override in init daemon_threads = true

now client requests daemonic , when main thread terminates, terminate. nice ! helps similar problem.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -