Skip to content

Instantly share code, notes, and snippets.

@ndamulelonemakh
Created April 18, 2020 16:39
Show Gist options
  • Select an option

  • Save ndamulelonemakh/e507c68fb2b3d9f223d6c2d723161303 to your computer and use it in GitHub Desktop.

Select an option

Save ndamulelonemakh/e507c68fb2b3d9f223d6c2d723161303 to your computer and use it in GitHub Desktop.
Creating python console executables with pyinstaller and argparse
"""
A simple python script that uses the psutil package to show processes running on a host machine.
"""
__version__ = '1.0.0'
__author__ = 'Ndamulelo N [email protected]'
import psutil
import argparse
"""
We use argeparse to allow the user to specify the limit on the number of processes to show.
Example usage: $ python proclist.py --limit 3
"""
parser = argparse.ArgumentParser(prog='ProcList',
description='Simple console application that show process info on the host machine')
parser.add_argument('--limit', type=int, help='Maximum number of processes to show')
arguments = parser.parse_args()
DEFAULT_LIMIT = 5
def main():
limit = arguments.limit or DEFAULT_LIMIT
for idx, proc in enumerate(psutil.process_iter(['pid', 'name'])):
print(proc.info)
if idx >= limit:
break
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment