Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "André Erdmann" <dywi@mailerd.de>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH 06/13] autobuild-run: explicitly close web file handles
Date: Wed, 25 Feb 2015 22:17:23 +0100	[thread overview]
Message-ID: <1424899050-24932-7-git-send-email-dywi@mailerd.de> (raw)
In-Reply-To: <1424899050-24932-1-git-send-email-dywi@mailerd.de>

Close urlopen() file handles as soon as possible
rather than waiting until their refcount drops to zero.

Signed-off-by: Andr? Erdmann <dywi@mailerd.de>
---
 scripts/autobuild-run | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/scripts/autobuild-run b/scripts/autobuild-run
index 5db21b1..fee68b7 100755
--- a/scripts/autobuild-run
+++ b/scripts/autobuild-run
@@ -59,6 +59,7 @@
 
 from __future__ import print_function
 
+import contextlib
 import csv
 from random import randint
 import subprocess
@@ -79,6 +80,7 @@ else:
     import urllib2 as _urllib
 
 urlopen = _urllib.urlopen
+urlopen_closing = lambda uri: contextlib.closing(urlopen(uri))
 
 if sys.hexversion >= 0x3000000:
     def decode_bytes(b):
@@ -101,8 +103,8 @@ def log_write(logf, msg):
     logf.flush()
 
 def check_version():
-    r = urlopen('http://autobuild.buildroot.org/version')
-    version = int(decode_bytes(r.readline()).strip())
+    with urlopen_closing('http://autobuild.buildroot.org/version') as r:
+        version = int(decode_bytes(r.readline()).strip())
     if version > VERSION:
         print("ERROR: script version too old, please upgrade.")
         sys.exit(1)
@@ -155,9 +157,10 @@ def get_toolchain_configs():
         - hostarch: the host architecture for which the toolchain is built
         - contents: an array of lines of the defconfig
     """
+    tc_cfg_uri = 'http://autobuild.buildroot.org/toolchains/configs/toolchain-configs.csv'
 
-    r = urlopen('http://autobuild.buildroot.org/toolchains/configs/toolchain-configs.csv')
-    l = decode_byte_list(r.readlines())
+    with urlopen_closing(tc_cfg_uri) as r:
+        l = decode_byte_list(r.readlines())
     configs = []
     for row in csv.reader(l):
         config = {}
@@ -171,8 +174,8 @@ def get_toolchain_configs():
         if hostarch != config["hostarch"]:
             continue
         config["libc"] = row[2]
-        r = urlopen(config["url"])
-        config["contents"] = decode_byte_list(r.readlines())
+        with urlopen_closing(config["url"]) as r:
+            config["contents"] = decode_byte_list(r.readlines())
         configs.append(config)
     return configs
 
-- 
2.3.0

  parent reply	other threads:[~2015-02-25 21:17 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-25 21:17 [Buildroot] [PATCH 00/13] autobuild-run: python3 compat and misc improvements André Erdmann
2015-02-25 21:17 ` [Buildroot] [PATCH 01/13] autobuild-run, python3: print is a function André Erdmann
2015-02-25 21:17 ` [Buildroot] [PATCH 02/13] autobuild-run, python3: urllib.request<>urllib2 André Erdmann
2015-02-25 21:17 ` [Buildroot] [PATCH 03/13] autobuild-run, python3: bytes<>str, decode() André Erdmann
2015-02-25 21:17 ` [Buildroot] [PATCH 04/13] autobuild-run, python3: configparser<>ConfigParser André Erdmann
2015-02-25 21:17 ` [Buildroot] [PATCH 05/13] autobuild-run: remove unneeded vars André Erdmann
2015-02-25 21:17 ` André Erdmann [this message]
2015-02-25 21:17 ` [Buildroot] [PATCH 07/13] autobuild-run: get host arch once André Erdmann
2015-02-25 21:17 ` [Buildroot] [PATCH 08/13] autobuild-run: sort imports alphabetically André Erdmann
2015-02-25 21:17 ` [Buildroot] [PATCH 09/13] autobuild-run: unify "which <prog>" code André Erdmann
2015-02-25 21:17 ` [Buildroot] [PATCH 10/13] autobuild-run: use a built-in has_prog() implementation André Erdmann
2015-02-25 21:17 ` [Buildroot] [PATCH 11/13] autobuild-run: move check_requirements() to SystemInfo André Erdmann
2015-02-25 21:17 ` [Buildroot] [PATCH 12/13] autobuild-run: encapsulate subprocess calls André Erdmann
2015-02-25 21:17 ` [Buildroot] [PATCH 13/13] autobuild-run: set locale to en_US or C André Erdmann
2015-02-26 10:08 ` [Buildroot] [PATCH 00/13] autobuild-run: python3 compat and misc improvements Thomas Petazzoni
2015-02-26 19:25   ` Thomas De Schampheleire
2015-03-01  0:09     ` André Erdmann
2015-03-01 21:17       ` Thomas De Schampheleire
2015-03-01 21:37         ` André Erdmann
2015-03-01 21:52           ` Thomas De Schampheleire
2015-03-02  8:36             ` Thomas Petazzoni
2015-03-02 20:00               ` André Erdmann
2015-03-15 13:36 ` Thomas Petazzoni

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1424899050-24932-7-git-send-email-dywi@mailerd.de \
    --to=dywi@mailerd.de \
    --cc=buildroot@busybox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox