Skip to content

Instantly share code, notes, and snippets.

@tkanerva
Created October 14, 2013 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkanerva/6979907 to your computer and use it in GitHub Desktop.
Save tkanerva/6979907 to your computer and use it in GitHub Desktop.
jython 2.7b2+ ends up with exhausting all file descriptors (ulimit=1024)
>>> import subprocess
>>> def ping(addr):
... cmd1 = '/bin/ping -c2 {addr}'.format(addr=addr)
... try:
... output = subprocess.check_output(cmd1.split(' '))
... except subprocess.CalledProcessError:
... retval = False
... min = 0
... else:
... head, _, rest = output.partition('mdev =')
... min, avg, max, mdev = rest[:-4].split('/')
... received = head.partition('packets transmitted,')[2][:2]
... retval = True if int(received) > 0 else False
... return (retval, float(min))
...
>>> a1='8.8.8.8'
>>> lst=[]
>>> for i in range(1024):
... lst.append( ping(a1) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment