7.22. Multiprocessing Client

7.22.1. SetUp

iris.py:

from dataclasses import dataclass

@dataclass
class Iris:
    sepal_length: float
    sepal_width: float
    petal_length: float
    petal_width: float
    species: str

    def sepal_area(self):
        return self.sepal_length * self.sepal_width

    def petal_area(self):
        return self.petal_length * self.petal_width

    def total_area(self):
        return self.sepal_area() + self.petal_area()

7.22.2. Client

  • Obiekt wysyłający dane multiprocessing-client.py:

import pickle
from multiprocessing.connection import Client
from iris import Iris


flower = Iris(
    sepal_length=5.1,
    sepal_width=3.5,
    petal_length=1.4,
    petal_width=0.2,
    species='setosa'
)

payload = pickle.dumps(flower)


ADDRESS = ('localhost', 6000)
PASSWORD = b'My voice is my password, verify me.'

connection = Client(ADDRESS, authkey=PASSWORD)
connection.send(payload)
connection.send('close')
connection.close()

7.22.3. Assignments