(local_host, local_port) = rsock.getsockname()
# Save local port information to file
- f = open(local_port_file, 'w')
- f.write("%d\n" % local_port)
- f.close()
+ with open(local_port_file, 'w') as f:
+ f.write("%d\n" % local_port)
# Wait until remote port information is available
while not os.path.exists(remote_port_file):
# the read operation returns empty string!
# Maybe a race condition?
for i in xrange(10):
- f = open(remote_port_file, 'r')
- remote_port = f.read()
- f.close()
+ with open(remote_port_file, 'r') as f:
+ remote_port = f.read()
if remote_port:
break
# TODO: Test connectivity!
# Create a ret_file to indicate success
- f = open(ret_file, 'w')
- f.write("0")
- f.close()
+ with open(ret_file, 'w') as f:
+ f.write("0")
STARTED = True