Created
January 23, 2018 15:26
-
-
Save itdaniher/b16e09a1f247790b111e1ce2bf99a69b to your computer and use it in GitHub Desktop.
functools.lru caches fds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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