Dalba has uploaded a new change for review. https://gerrit.wikimedia.org/r/321727
Change subject: throttle.py: Make sure openned files are closed properly ...................................................................... throttle.py: Make sure openned files are closed properly Bug: T124725 unclosed and python raised ResourceWarning upon exit. Change-Id: I6af4adae0e731cbcc8ff0c002b7d188f4e874520 --- M pywikibot/throttle.py 1 file changed, 6 insertions(+), 6 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/27/321727/1 diff --git a/pywikibot/throttle.py b/pywikibot/throttle.py index d125df1..9a38e46 100644 --- a/pywikibot/throttle.py +++ b/pywikibot/throttle.py @@ -204,12 +204,13 @@ self.checktime = 0 processes = [] try: - f = open(self.ctrlfilename, 'r') + with open(self.ctrlfilename, 'r') as f: + lines = f.readlines() except IOError: return else: now = time.time() - for line in f.readlines(): + for line in lines: try: line = line.split(' ') this_pid = int(line[0]) @@ -225,12 +226,11 @@ 'site': this_site}) processes.sort(key=lambda p: p['pid']) 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)s %(time)s %(site)s\n" % p) except IOError: return - f.close() def wait(self, seconds): """Wait for seconds seconds. -- To view, visit https://gerrit.wikimedia.org/r/321727 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6af4adae0e731cbcc8ff0c002b7d188f4e874520 Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Dalba <dalba.w...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits