Unleash Multiprocessing with Python and gRPC

Multiprocessing is hard, here’s a practical example to be on the right track in 5mins.

François Paupier
8 min readAug 10, 2021
Separate color lines illustrating separate processes in your program.
Photo by Isaac Quesada from Pexels

If you’re reading this, it’s likely you’re in the optimization phase of your project and want to reduce your application’s runtime. In this article, I want to answer the following question:

How to address an embarrassingly parallel workload in Python using gRPC servers ?

I’m a freelance machine learning engineer and I got called for such a project: To reduce the runtime of a computer vision workload.

I’ve taken the gist out of this experience and here’s what I learned.

I split this article into two parts: first a light theoretical refresher, then a practical tutorial:

  1. We’ll briefly highlight the differences between multi-threading and multiprocessing, pinpointing which use cases are better addressed by one or the other.
  2. Then we’ll get our hands dirty and walk through a use case of optimizing a computer vision app.

We’ll work on a simple optical character recognition (OCR) use case but feel free to adapt it to your workflow!

Bonus — War stories and several gRPC tips & tricks are distilled along the way! 😉

--

--

François Paupier

Machine Learning — Data pipeline — Software Engineering