Coder Social home page Coder Social logo

inter_process_communication's Introduction

Inter-process communication

This Python application launches a couple of processes which communicate with each other using the publish-subscribe messaging pattern.

There are 5 main objects :

  • MotionDetector (Publisher) : Gets a message from the Flask API, creates an object of the class MotionVector and adds this object to the queue
  • SingleShotDetector (Publisher-Subcriber) : Gets the messages from the MotionVector's queue, process them and puts them in the DetectionVector's queue.
  • Logger (Subscriber) : Reads messages from the both queues and logs them to the standard output.
  • MotionVector (Topic) : Class which allows us to create messages under a specific format
  • DetectionVector (Topic) : Class which allows us to create messages under a specific format

To be able to correctly share data between processes, the decision to use Queues was made.
Queues are using pipes and a few locks/semaphores, so this guarantees us that data will not be corrupted.

Test the application

Flask is using PORT 5000, make sure that the port is not already in use.

  • 1 : Open the folder inter_process_communication in a terminal window

  • 2 : Copy and past this shell command in the terminal window : docker-compose -f devops/docker_compose_inter_process_comm.yml up --build
    If everything went good you should see something similar to this in your terminal window : alt text

  • 3 : It's time to open the Swagger ! (API's documentation)
    Copy and paste this link into your web browser : http://0.0.0.0:5000/doc The swagger must open in your web browser : alt text

  • 4 : Click on "POST" row, it will open, click on try it out
    Write a message and click on Execute If everything went good flask has returned 201 : created alt text

In your terminal window you should see this message printed 2 times, logger consumes 2 queues, first the message will be taken from the first queue and printed and then when the process SingleShotDetector will process the message it will exist in the second queue and the logger will print it a second time.

alt text

To stop the docker container :

Please use the command docker stop $(docker ps -a -q) to stop the application.
If you will try to stop it only with the CTRL + C it won't stop correctly as the application has not only one process running.

inter_process_communication's People

Contributors

igondiu avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.