Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'socket': 0.05; 'badly': 0.07; 'returned.': 0.07; 'subject:two': 0.07; 'python': 0.09; 'command-line': 0.09; 'oh,': 0.09; 'ping': 0.09; 'cc:addr:python- list': 0.10; ':-)': 0.13; '"good': 0.16; 'enough.': 0.16; 'getaddrinfo': 0.16; 'received:mac.com': 0.16; 'roy': 0.16; 'simpler,': 0.16; 'subject:questions': 0.16; 'time.time()': 0.16; 'wing': 0.16; 'wrote:': 0.17; 'exists': 0.17; 'received:10.0.1': 0.17; 'specify': 0.17; 'thanks,': 0.18; '>>>': 0.18; 'import': 0.21; 'cc:2**1': 0.24; 'cc:addr:python.org': 0.25; 'looks': 0.26; 'am,': 0.27; "doesn't": 0.28; 'this?': 0.28; '>>>>': 0.29; 'faster,': 0.29; 'ray': 0.29; 'url:mailman': 0.29; 'case,': 0.29; "i'm": 0.29; 'seconds': 0.30; '(and': 0.32; 'url:python': 0.32; 'print': 0.32; 'url:listinfo': 0.32; 'utility': 0.33; 'received:10.0': 0.33; 'server': 0.35; 'nov': 0.35; 'path': 0.35; 'received:17': 0.35; 'doing': 0.35; 'pm,': 0.35; 'really': 0.36; 'but': 0.36; 'url:org': 0.36; 'cc:no real name:2**1': 0.36; 'url:library': 0.36; 'why': 0.37; 'subject:: ': 0.38; 'fact': 0.38; 'url:docs': 0.38; 'received:10': 0.38; 'takes': 0.39; 'url:mail': 0.40; 'days': 0.60; 'from:no real name:2**0': 0.60; 'more': 0.63; 'within': 0.64; 'charset:windows-1252': 0.65; 'response.': 0.67; 'smith': 0.71; 'article': 0.78; 'directly.': 0.78; 'william': 0.78; 'mistaken': 0.84; '"it': 0.91; 'incredibly': 0.96 MIME-version: 1.0 Content-type: text/plain; charset=windows-1252 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.9.8185,1.0.431,0.0.0000 definitions=2012-11-14_05:2012-11-14, 2012-11-14, 1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 suspectscore=0 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=6.0.2-1203120001 definitions=main-1211140111 Subject: Re: Subprocess puzzle and two questions From: wrw@mac.com In-reply-to: Date: Wed, 14 Nov 2012 09:37:12 -0500 Content-transfer-encoding: quoted-printable References: To: Roy Smith X-Mailer: Apple Mail (2.1499) Cc: python-list@python.org, wrw@mac.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 59 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1352907443 news.xs4all.nl 6943 [2001:888:2000:d::a6]:47447 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:33341 On Nov 14, 2012, at 9:22 AM, Roy Smith wrote: > In article , > William Ray Wing wrote: >=20 >> On Nov 13, 2012, at 11:41 PM, Roy Smith wrote: >>=20 >>> In article , >>> wrw@mac.com wrote: >>>=20 >>>> I need to time the operation of a command-line utility = (specifically=20 >>>> nslookup) from within a python program I'm writing. >>>=20 >>> Ugh. Why are you doing this? Shelling out to nslookup is an = incredibly=20 >>> slow and clumsy way of doing name translation. What you really want = to=20 >>> be doing is calling getaddrinfo() directly. >>>=20 >>> See http://docs.python.org/2/library/socket.html#socket.getaddrinfo = for=20 >>> details. >>> --=20 >> Because, unless I'm badly mistaken (very possible), getaddrinfo = doesn't let=20 >> me specify the server from which the name is returned. I'm really not = after=20 >> the name, what I'm REALLY after is the fact that a path exists to the = name=20 >> server I specify (and how long it takes to respond). In the "good old = days" I=20 >> would just have ping'd it, but these days more and more DNS boxes = (and=20 >> servers of all sorts) are shutting off their ping response. >>=20 >> Thanks, Bill >=20 > Oh, my. You're using DNS as a replacement for ping? Fair enough. In=20= > that case, all you really care about is that you can connect to port = 53=20 > on the server... >=20 > import socket > import time > s =3D socket.socket() > t0 =3D time.time() > s.connect(('8.8.8.8', 53)) > t1 =3D time.time() > print "it took %f seconds to connect" % (t1 - t0) > --=20 > http://mail.python.org/mailman/listinfo/python-list Now THAT looks better. Simpler, cleaner, (longer, taller, stronger, = faster, cheaper=85 :-) Thanks, Bill=