Fix ResourceWarning: unclosed file (#681)

Signed-off-by: Mickaël Schoentgen <contact@tiger-222.fr>
This commit is contained in:
Mickaël Schoentgen
2019-01-08 09:59:23 +01:00
committed by Libin Yang
parent 3dc50529ca
commit 2d70e9f747
10 changed files with 104 additions and 110 deletions

View File

@ -17,13 +17,12 @@ while True:
print('Server received', repr(data))
filename = 'mytext.txt'
f = open(filename, 'rb')
in_data = f.read(1024)
while (in_data):
conn.send(in_data)
print('Sent ', repr(in_data))
in_data = f.read(1024)
f.close()
with open(filename, 'rb') as f:
in_data = f.read(1024)
while in_data:
conn.send(in_data)
print('Sent ', repr(in_data))
in_data = f.read(1024)
print('Done sending')
conn.send('Thank you for connecting')