Since Python 3.12 the standard library has included an `os.unshare` function. Use it if it is available. Signed-off-by: Jeremy Sowden --- iptables-test.py | 9 ++++++++- xlate-test.py | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/iptables-test.py b/iptables-test.py index 66db552185bc..40ed77035c02 100755 --- a/iptables-test.py +++ b/iptables-test.py @@ -572,7 +572,14 @@ def show_missing(): print('\n'.join(missing)) def spawn_netns(): - # prefer unshare module + # prefer stdlib unshare function ... + try: + os.unshare(os.CLONE_NEWNET) + return True + except Exception as e: + pass + + # ... or unshare module try: import unshare unshare.unshare(unshare.CLONE_NEWNET) diff --git a/xlate-test.py b/xlate-test.py index 1c8cfe71ffd4..247852939c9e 100755 --- a/xlate-test.py +++ b/xlate-test.py @@ -203,7 +203,14 @@ def load_test_files(): def spawn_netns(): - # prefer unshare module + # prefer stdlib unshare function ... + try: + os.unshare(os.CLONE_NEWNET) + return True + except Exception as e: + pass + + # ... or unshare module try: import unshare unshare.unshare(unshare.CLONE_NEWNET) -- 2.51.0