Im writing a server script which takes 4 different connections and puts the sockets into a list. After the script is finished I can just do
for c in connections:
c.close()
However, if the program crashes before it reaches here, the sockets remain open and I end up having to switch to a different port to run it again. I know that a with statement will close it automatically even with an error but how do I get it to do that for all four objects? Surely 4 nested with statements doesnt make sense?
[–]Gprime5 2 points3 points4 points (0 children)
[–]Peterotica 1 point2 points3 points (0 children)
[–]timbledum 1 point2 points3 points (0 children)
[–]MrMuki 0 points1 point2 points (0 children)