Pascal de Sélys
Pascal de Sélys

Reputation: 137

multiprocessing concurrent:concurrent.future, multiprocessing, celery, etc

I'm gonna need your lights. I have been looking for a suitable solution for asynchronous multiprocessing for quite some time. I came across many topics that use different techniques, such as celery, multiprocessing, concurrent.future, asyncio. after several readings I happen to be trying to make concurrent. I would like to create several bot and have them communicate with the main program. Here is a code idea

import random import time 

from multiprocessing import Process, Queue 
from robotic import Robot


def robots(name,force,lifepoints):
    life = lifepoints
    robot = Robot(name,force)
    point = int()
    result = int()
    while life is True:
        result = robot.force(point)
        time.sleep(2)


robot = Process(target=robots, args=('bot1',1,100)) 
robot2 = Process(target=robots, args=('bot2',1,100)) 
combat = True

while combat is True:
    print(robot.get(result))
    robot.put(point=2)

I would like to be able to run 2 infinite loops with the creation of a robot with these parameters and then be able to access from outside this is process to variable and have the ability to change their data. I don't know how to do that, thanks in advance.

Upvotes: 0

Views: 88

Answers (1)

ramazan polat
ramazan polat

Reputation: 7900

You are starting 2 processes correctly but unlike threads, processes use different memory space, think them as 2 separate programs running. So in order to make them connect you need interprocess message passing which can be done using multiprocessing.Queue().

Upvotes: 2

Related Questions