git://git.onelab.eu
/
nepi.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
systematic use of context managers for dealing with files instead of open()/close...
[nepi.git]
/
src
/
nepi
/
resources
/
linux
/
scripts
/
fd-udp-connect.py
diff --git
a/src/nepi/resources/linux/scripts/fd-udp-connect.py
b/src/nepi/resources/linux/scripts/fd-udp-connect.py
index
83bd845
..
7096cf1
100644
(file)
--- a/
src/nepi/resources/linux/scripts/fd-udp-connect.py
+++ b/
src/nepi/resources/linux/scripts/fd-udp-connect.py
@@
-114,9
+114,8
@@
if __name__ == '__main__':
(local_host, local_port) = rsock.getsockname()
# Save local port information to file
(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):
# Wait until remote port information is available
while not os.path.exists(remote_port_file):
@@
-130,9
+129,8
@@
if __name__ == '__main__':
# the read operation returns empty string!
# Maybe a race condition?
for i in xrange(10):
# 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
if remote_port:
break
@@
-157,9
+155,8
@@
if __name__ == '__main__':
# TODO: Test connectivity!
# Create a ret_file to indicate success
# 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
STARTED = True