Skip to content

Latest commit

 

History

History
147 lines (92 loc) · 3.28 KB

README.md

File metadata and controls

147 lines (92 loc) · 3.28 KB

gRPC in the snake pit

Getting started with

  • gRPC
  • Python
  • Test Driven Development
  • Docs-as-code
  • Visual Studio Code

Check work environment

Check if your machine already provides Python 3.12 and VS Code

Open a Terminal with a bash shell. On Windows use git-bash and check for them:

code --version
python3 --version

Positive responses and fitting Python version? Then your're all set. Skip next following and proceed with the next but one chapter.

Negative responses? Complete work environment. You may be guided by the next chapter.

Set up work environment

On Windows

You might want to use the package manager Scoop for that. In that case you might need to install it following the instructions on their website.

Close the shell (it was one with a Powershell). Important environment variables will be available only in freshly opened shells You'll open a new Terminal with git-bash. In the processing steps.

Install Python 3.12 via Scoop:

scoop bucket add versions
scoop install python312

Install VSCode via Scoop:

scoop bucket add extras
scoop install vscode

On Linux (Ubuntu 22.04)

See Install Python 3.12 on Ubuntu 22.04

See Install VSCode on Ubuntu 22.04

In GitHub Codespace

If not already done, create fork of this repository.

In your fork create Codespace.

You're all set.

Build - Run - Edit - Workflow

Open a Terminal and ake sure that the current work directory is the repository root folder.

Install global python package requirements:

python3 -m pip install -r requirements.txt

Create virtual python development environment:

pipenv install --dev

Get rid of annoying pipenv warnings later on:

export PIPENV_VERBOSITY=-1   # Supress warnings when pipenv started being already in virtual environment

Build

Change into source folder:

cd src

Generate python code from message definitions in protobuf language:

pipenv run python3 -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. grpc_in_the_snake_pit/helloworld.proto

Run

Start the server in an own subprocess by:

pipenv run python3 -m grpc_in_the_snake_pit.server &

Now the server runs persistently in an endless loop in the background.

Start the client by:

pipenv run python3 -m grpc_in_the_snake_pit.client

The client sends only one message to the server and waits for the reply before terminating itself.

You need to re-start the client again to repeat the interchange of that single message.

You can stop the server by killing the subprocess the server runs in. Because it's the only (and so most recent) subprocess of your bash session it's pid (process identification number) is in built-in variable $!. It can be killed via:

kill  $!

Other actions

Make workenvironment clean

Remove relicts of code generation and run/test:

rm -rf **/*_pb2*.py
rm -rf **/__pycache__ ; rm -rf **/*.pyc
rm -f .coverage ; rm -rf .coverage-dir

Remove work environment:

rm -f Pipfile.lock 
rm -rf .venv/ ; git restore .venv/

Edit