Intercommunication between processes

Sometimes, you will have a process that needs to pass or exchange information with other processes during runtime. The multiprocessing module has a Queue class that implements a special list, within which a process can insert and consume data. There are two methods available inside of this class: get() and put(). The put() method is used to add data to the Queue, whereas getting data from the queue is done via the get() method. In the next example, we will use Queue to pass data from a subprocess to a parent process:

import multiprocessingfrom netmiko import ConnectHandlerfrom devices import R1, SW1, SW2, SW3, SW4from pprint import pprintnodes = [R1, SW1, SW2, SW3, SW4]def connect_to_dev(device, mp_queue ...

Get Hands-On Enterprise Automation with Python. now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.