def main()filename os path join(os path dirname(__file__)"car_registrations dat"cars load(filenameprint("loaded { car registrationsformat(len(cars))requesthandler cars cars server none tryserver carregistrationserver(("" )requesthandlerserver serve_forever(except exception as errprint("error"errfinallyif server is not noneserver shutdown(save(filenamecarsprint("saved { car registrationsformat(len(cars))we have stored the car registration data in the same directory as the program the cars object is set to dictionary whose keys are license strings and whose values are car objects normally servers do not print anything since they are typically started and stopped automatically and run in the backgroundso usually they report on their status by writing logs ( using the logging modulehere we have chosen to print message at start-up and shutdown to make testing and experimenting easier our request handler class needs to be able to access the cars dictionarybut we cannot pass the dictionary to an instance because the server creates the instances for us--one to handle each request so we set the dictionary to the requesthandler cars class variable where it is accessible to all instances we create an instance of the server passing it the address and port it should operate on and the requesthandler class object--not an instance an empty string as the address indicates any accessible ipv address (including the current machinelocalhostthen we tell the server to serve requests forever when the server shuts down (we will see how this happens further on)we save the cars dictionary since the data may have been changed by clients def load(filename)trywith contextlib closing(gzip open(filename"rb")as fhreturn pickle load(fhexcept (environmenterrorpickle unpicklingerroras errprint("server cannot load data{ }format(err)sys exit(