The PyTheorem repository helps in the learning of the python language and contains the algorithms, abstract data
types and implementation of them including the
interview preparation algorithms in Python language.
Although this layout is pretty straightforward, it has several drawbacks that arise as the app complexity increases.
For example, it will be hard for you to reuse the application logic in other projects because all the functionality is
bundled in webapp/__init__.py.
If you split this functionality into modules instead, then you could reuse complete modules across different projects.
/
├── adts # an adts package/
│ ├── array # an array package/
│ ├── graph # a graph package/
│ │ ├── __init__.py # The package initializer
│ │ ├── README.md # Instructions and helpful links
│ │ └── / #
│ ├── hash # a hash package/
│ ├── heap # a heap package/
│ ├── iterator # an iterator package/
│ ├── lang # a lang package/
│ ├── linkedlist # a linkedlist package/
│ ├── list # a list package/
│ ├── logs # a logs package/
│ ├── map # a map package/
│ ├── queue # a queue package/
│ ├── search # a search package/
│ ├── security # a security package/
│ ├── sort # a sort package/
│ ├── stack # a stack package/
│ ├── text # a text package/
│ ├── time # a time package/
│ ├── tree # a tree package/
│ ├── trie # a trie package/
│ ├── __init__.py # The package initializer
│ └── README.md # The README file of ews module
├── algos # an algos package/
│ ├── array # an array package/
│ ├── graph # a graph package/
│ │ ├── __init__.py # The package initializer
│ │ ├── README.md # Instructions and helpful links
│ │ └── _ # The package initializer
│ ├── hash # a hash package/
│ ├── heap # a heap package/
│ ├── iterator # an iterator package/
│ ├── lang # a lang package/
│ ├── linkedlist # a linkedlist package/
│ ├── list # a list package/
│ ├── logs # a logs package/
│ ├── map # a map package/
│ ├── queue # a queue package/
│ ├── search # a search package/
│ ├── security # a security package/
│ ├── sort # a sort package/
│ ├── stack # a stack package/
│ ├── text # a text package/
│ ├── time # a time package/
│ ├── tree # a tree package/
│ ├── trie # a trie package/
│ ├── __init__.py # The package initializer
│ └── README.md # The README file of ews module
├── aptitude # an aptitude package/
├── aws # an AWS package/
├── configs # The configs package
├── core # The core package
├── domain # a domain package/
├── games # a games package/
├── quiz # a quiz package/
├── README.md # Instructions and helpful links
├── requirements.txt # a list of package dependencies
├── robots.txt # tells which URLs the search engine crawlers can access on your site
└── / #
| Folder | Description |
|---|---|
| /apidoc | the doc-generated API docs |
| /code | the project files |
| /doc | the documentation |
| /lib | the C-language libraries |
| /scripts or /bin | the that kind of command-line interface stuff |
| /tests | the tests of the project |
python3 --version
python3 -m pip --version
python3 -m ensurepip --default-pippython3 -m pip install virtualenv
python3 -m venv venv
source deactivate
source venv/bin/activate
source is Linux/macOS command and doesn't work in Windows.
- Windows
venv\Scripts\activate- Mac OS/Linux
source venv/bin/activate
OR
. ./venv/bin/activate Output:
(venv) <UserName>@<HostName> PyTheorem %
The parenthesized (venv) in front of the prompt indicates that you’ve successfully activated the virtual
environment.
deactivateOutput:
<UserName>@<HostName> PyTheorem %
pip install --upgrade pip- Install at the system level
brew install python-requests- Install in specific Virtual Env
pip install requests
pip install beautifulsoup4
python -m pip install requestspip install -r requirements.txtpip freeze > requirements.txtpython -m buildSet a local configuration file.
Create or update local .env configuration file.
pip install python-dotenv
cp default.env .envNow, update the default local configurations as follows:
# App Configs
APP_HOST = 0.0.0.0
HOST = 0.0.0.0
APP_PORT = 8080
PORT = 8080
APP_ENV = develop
DEBUG = False
#
# Pool Configs
#
DEFAULT_POOL_SIZE = 1
RDS_POOL_SIZE = 1
#
# Logger Configs
#
LOG_FILE_NAME = 'PyTheorem.log'
#
# Database Configs
#
DB_HOSTNAME = 127.0.0.1
DB_PORT =
DB_NAME = PyTheorem
DB_USERNAME = PyTheorem
DB_PASSWORD = Password
By default, Flask will run the application on port 5000.
python -m flask --app webapp run --port 8080 --debugBy default, Flask runs the application on port 5000.
python wsgi.py
OR
#flask --app wsgi run
python -m flask --app wsgi run
# http://127.0.0.1:5000/PyTheorem
OR
python -m flask --app wsgi run --port 8080 --debug
# http://127.0.0.1:8080/PyTheorem
OR
# Production Mode
# equivalent to 'from app import app'
gunicorn wsgi:app
# gunicorn -w <n> 'wsgi:app'
gunicorn -w 2 'wsgi:app'
# http://127.0.0.1:8000/PyTheorem
gunicorn -c gunicorn.conf.py wsgi:app
# http://127.0.0.1:8080/PyTheorem
Note:- You can stop the development server by pressing Ctrl+C in your terminal.
- [IWS on port 8080](http://127.0.0.1:8080/PyTheorem)
- [IWS on port 8000](http://127.0.0.1:8000/PyTheorem)
- [IWS on port 5000](http://127.0.0.1:5000/PyTheorem)python -m unittest
python -m unittest discover -s ./pytheorem/tests -p "test_*.py"# Run this in a separate terminal
# so that the load generation continues and you can carry on with the rest of the steps
kubectl run -i --tty load-generator --rm --image=busybox:1.28 --restart=Never -- /bin/sh -c "while sleep 0.01; do wget -q -O- http://php-apache; done"- Formula
RPS = TotalCore * (1/TaskDurationInSeconds)
i.e.:
4 * (1000/100) = 40
| Total Cores | Task Duration | RPS |
|---|---|---|
| 4 | 100ms | 40 |
| 4 | 50ms | 80 |
| 4 | 10ms | 400 |
- Build a Scalable Flask Web Project From Scratch
- Gunicorn - WSGI server
- Python Packaging User Guide
- The Twelve Factors App
- werkzeug examples
- Lamport Clocks
- Lamport Clocks: Determining the Order of Events in Distributed Systems
- Lamport Logical Clock
- Vector Clock
- Time in Distributed Systems Lamport Timestamps
- Rohtash Lakra