Skip to content

Instantly share code, notes, and snippets.

@itdaniher
Created January 23, 2018 15:26
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 itdaniher/b16e09a1f247790b111e1ce2bf99a69b to your computer and use it in GitHub Desktop.
Save itdaniher/b16e09a1f247790b111e1ce2bf99a69b to your computer and use it in GitHub Desktop.
functools.lru caches fds
import os
import sys
import traceback
import pyroute2.netns
i = 0
import functools
@functools.lru_cache(maxsize=1024)
def get_fd_from_netnspath(netnspath):
return os.open(netnspath, os.O_RDONLY)
while True:
try:
pyroute2.netns.setns(get_fd_from_netnspath('/proc/1/ns/net'))
except:
traceback.print_exc(file=sys.stderr)
print(i)
break
i += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment