Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #26310

Pass data to a subprocess

Date 2012-07-31 14:56 +0100
Subject Pass data to a subprocess
From andrea crotti <andrea.crotti.0@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2780.1343742999.4697.python-list@python.org> (permalink)

Show all headers | View raw


I'm having fun in the world of multiprocessing, and I would like some
suggestions.

For example suppose I want to create many processes and pass them some
data to process (also why they are running).

I found many nice things (Pipe, Manager and so on), but actually even
this seems to work:


class MyProcess(Process):
    def __init__(self):
        Process.__init__(self)
        self.ls = []

    def __str__(self):
        return str(self.ls)

    def add(self, ls):
        self.ls += ls

    def run(self):
        print("running the process in another subprocess")


def procs():
    mp = MyProcess()
    mp.start()
    # with the join we are actually waiting for the end of the running time
    mp.join()
    mp.add([1,2,3])
    mp.add([2,3,4])
    print(mp)


Which is a bit surprising, because it means that I can pass data to an
object that is running on another process.
Is it because of some magic in the background and can I rely on that or
simply I didn't understand how it works?

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Pass data to a subprocess andrea crotti <andrea.crotti.0@gmail.com> - 2012-07-31 14:56 +0100

csiph-web