jenkins-bot merged this change.

View Change

Approvals: Dvorapa: Looks good to me, approved jenkins-bot: Verified
[IMPR] Always close files finally in throttle.py

- move close() statement to finally section in checkMultiplicity()
- use with statement in drop()

Change-Id: I4dbb78efa546067dc9916476c9f576b92fb8d921
---
M pywikibot/throttle.py
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/pywikibot/throttle.py b/pywikibot/throttle.py
index 91b3318..047e67c 100644
--- a/pywikibot/throttle.py
+++ b/pywikibot/throttle.py
@@ -121,6 +121,7 @@
'site': this_site})
if not pid and this_pid >= my_pid:
my_pid = this_pid + 1 # next unused process id
+ finally:
f.close()

if not pid:
@@ -131,13 +132,12 @@
'site': mysite})
processes.sort(key=lambda p: (p['pid'], p['site']))
try:
- f = open(self.ctrlfilename, 'w')
- for p in processes:
- f.write('%(pid)s %(time)s %(site)s\n' % p)
+ with open(self.ctrlfilename, 'w') as f:
+ for p in processes:
+ f.write('{pid} {time} {site}\n'.format(**p))
except IOError:
pass
- else:
- f.close()
+
self.process_multiplicity = count
pywikibot.log(
'Found {0} {1} processes running, including this one.'.format(

To view, visit change 606172. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I4dbb78efa546067dc9916476c9f576b92fb8d921
Gerrit-Change-Number: 606172
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Dvorapa <dvorapa@seznam.cz>
Gerrit-Reviewer: jenkins-bot (75)