0

I am using the "run" method in python that is running the web server. I want to make it thread safe by using mutex. How can i do this and where should i locate the mutex? Thanks.

def run(serverClass=FlsLdkServiceThreadedHttpServer, handlerClass=FlsLdkServiceRequestHandler, hostName="localhost", port=1111):       

    serverAddress = (hostName, int(port))
    httpd = serverClass(serverAddress, handlerClass)
    logging.info("start")
    if sConfigIsSecure == "Yes":
        httpd.socket = ssl.wrap_socket(httpd.socket, certfile=sConfigCert, keyfile=sConfigPrivKey, server_side=True)
    try:        
        httpd.serve_forever()
    except KeyboardInterrupt:
        pass
    httpd.server_close()
    logging.info('Stop')
  • 1
    whats not thread safe here? – Nullman May 27 '19 at 13:04
  • Because im using several threads and i dont want them going to the critical code at the same time and cause starvation or deadlock – asdsmk2 May 27 '19 at 14:03
  • you're probably looking for [semaphore](https://docs.python.org/3/library/threading.html#semaphore-objects) also, [here](https://stackoverflow.com/questions/31508574/semaphores-on-python) is a usage example – Nullman May 27 '19 at 14:07

0 Answers0