Mailinglist Archive: opensuse-buildservice (239 mails)

< Previous Next >
Re: [opensuse-buildservice] osc r7259 (timeout) depends on Python 2.6
On 2009-05-06 12:32:26 +0200, Peter Poeml wrote:
TypeError: urlopen() got an unexpected keyword argument 'timeout'
[1] 9270 exit 1 osc rdelete home:poeml:branches:Subversion

the timeout argument to urllib2.urlopen was introduced with Python 2.6,
as it seems.

Hmm yes it seems so (I only tested it with python26:) ).

One way to work around would be to set socket.setdefaulttimeout(timeout);
possibly only for certain commands; or globally if it doesn't have negative
effects.

What do you think?
I think this should be ok - in the end urllib2 passes the timeout parameter
to httplib which passes it to the socket module. Using a global timeout for
all osc requests won't harm IMHO (if some command doesn't need it can use e.g.
http_GET(url, timeout=None) to disable the default timeout).
Does the attached patch work with python24?


Marcus
Index: core.py
===================================================================
--- core.py (Revision 7273)
+++ core.py (Arbeitskopie)
@@ -22,6 +22,7 @@
import conf
import subprocess
import re
+import socket
try:
from xml.etree import cElementTree as ET
except ImportError:
@@ -1538,9 +1539,12 @@

if conf.config['debug']: print method, url

+ old_timeout = socket.getdefaulttimeout()
+ socket.setdefaulttimeout(timeout)
try:
- fd = urllib2.urlopen(req, data=data, timeout=timeout)
+ fd = urllib2.urlopen(req, data=data)
finally:
+ socket.setdefaulttimeout(old_timeout)
if hasattr(conf.cookiejar, 'save'):
conf.cookiejar.save(ignore_discard=True)

< Previous Next >
Follow Ups
References