networking if car is not noneif car mileage mileagecar mileage mileage return (truenonereturn (false"cannot wind the odometer back"return (false"this license is not registered"in this method we can do one check without acquiring lock at all but if the mileage is non-negative we must acquire lock and get the relevant carand if we have car ( if the license is valid)we must stay within the scope of the lock to change the mileage as requested--or to return an error tuple if no car has the given license (car is none)we drop out of the with statement and return an error tuple it would seem that if we did the validation in the client we could avoid some network traffic entirelyfor examplethe client could give an error message (or simply preventnegative mileages even though the client ought to do thiswe must still have the check in the server since we cannot assume that the client is bug-free and although the client gets the car' mileage to use as the default mileage we cannot assume that the mileage entered by the user (even if it is greater than the current mileageis validbecause some other client could have increased the mileage in the meantime so we can only do the definitive validation at the serverand only within the scope of lock the change_owner(method is very similarso we won' reproduce it here def new_registration(selflicenseseatsmileageowner)if not licensereturn (false"cannot set an empty license"if seats not in { }return (false"cannot register car with invalid seats"if mileage return (false"cannot set negative mileage"if not ownerreturn (false"cannot set an empty owner"with self carslockif license not in self carsself cars[licensecar(seatsmileageownerreturn (truenonereturn (false"cannot register duplicate license"again we are able to do lot of error checking before accessing the registration databut if all the data is valid we acquire lock if the license is not in the requesthandler cars dictionary (and it shouldn' be since new registration should have an unused license)we create new car object and store it in the dictionary this must all be done within the scope of the same lock because we must not allow any other client to add car with this license in the time be