How to use sys to return mpiexec -n parameter in program?

Is there a way to use the sys module in Python to return an mpiexec -n parameter?

For example, say we run in Git Bash: mpiexec -n 6 python

How do we return the number after -n within the program? Will os.environ or some sort of sys module (or click) help with achieving this?


from mpi4py import MPI
nprocs = comm.Get_size()

It is possible that your MPI implementation also makes an environment variable available, but that’s implementation dependent.