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


Groups > comp.lang.python > #5775

Problem with multiprocessing

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <abate@pps.jussieu.fr>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'handled': 0.03; 'socket': 0.04; '(using': 0.05; 'library,': 0.05; 'received:134': 0.05; 'sys': 0.05; 'nasty': 0.07; 'prototyping': 0.07; 'raised': 0.07; 'python': 0.08; "(i'm": 0.09; '21,': 0.09; '__name__': 0.09; 'connect,': 0.09; 'library...': 0.09; 'ping': 0.09; 'spawn': 0.09; 'subject:Problem': 0.09; 'def': 0.12; 'server,': 0.12; "'__main__':": 0.16; '*args,': 0.16; '__init__': 0.16; 'expected.': 0.16; 'keyerror:': 0.16; 'nodes': 0.16; 'overflow': 0.16; 'result)': 0.16; 'shed': 0.16; 'temp': 0.16; 'yet...': 0.16; 'skip:" 40': 0.16; 'stack': 0.16; 'traceback': 0.16; '(most': 0.16; 'trace': 0.19; 'skip:m 30': 0.21; 'maybe': 0.23; 'explore': 0.23; 'last):': 0.23; 'structure': 0.23; 'url:wiki': 0.23; 'code': 0.24; 'library.': 0.25; 'receives': 0.25; 'handles': 0.26; 'pass': 0.27; 'tried': 0.27; "i'm": 0.27; 'thanks': 0.28; 'raise': 0.28; 'problem': 0.28; 'process,': 0.29; 'import': 0.29; 'skip:- 70': 0.29; 'server': 0.29; '24,': 0.29; 'class': 0.29; 'bit': 0.30; 'all,': 0.30; 'none,': 0.30; "didn't": 0.31; 'print': 0.31; 'skip:- 40': 0.32; "skip:' 10": 0.32; 'listening': 0.32; 'propose': 0.32; 'to:addr:python-list': 0.33; 'actually': 0.33; '----': 0.33; 'machine': 0.33; 'error': 0.33; '...': 0.34; 'file': 0.34; 'light': 0.34; 'there': 0.35; 'header:User-Agent:1': 0.35; 'fails': 0.35; 'using': 0.35; 'idea': 0.36; 'charset:us-ascii': 0.36; 'created': 0.36; 'connection': 0.37; 'something': 0.37; 'http': 0.37; 'logging': 0.37; 'url:en': 0.37; 'communicate': 0.37; 'pretty': 0.37; 'two': 0.37; 'url:org': 0.38; 'run': 0.38; 'but': 0.38; 'some': 0.38; 'skip:s 20': 0.39; 'should': 0.39; 'client': 0.39; 'requests': 0.39; 'list,': 0.39; 'subject:with': 0.39; 'to:addr:python.org': 0.39; 'more': 0.60; 'below': 0.61; 'back': 0.63; 'here': 0.66; 'share': 0.67; 'connection,': 0.73; '750,': 0.84; 'dispatched': 0.84; 'manager).': 0.84; 'node': 0.84
X-Ids 164
Date Thu, 19 May 2011 15:10:57 +0200
From Pietro Abate <Pietro.Abate@pps.jussieu.fr>
To python-list@python.org
Subject Problem with multiprocessing
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Disposition inline
X-Operating-System GNU/Linux
User-Agent Mutt/1.5.20 (2009-06-14)
X-Miltered at jchkmail.jussieu.fr with ID 4DD516E3.000 by Joe's j-chkmail (http : // j-chkmail dot ensmp dot fr)!
X-j-chkmail-Enveloppe 4DD516E3.000/134.157.168.1/hydrogene.pps.jussieu.fr/hydrogene.pps.jussieu.fr/<abate@pps.jussieu.fr>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1792.1305810661.9059.python-list@python.org> (permalink)
Lines 125
NNTP-Posting-Host 82.94.164.166
X-Trace 1305810662 news.xs4all.nl 49047 [::ffff:82.94.164.166]:42910
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:5775

Show key headers only | View raw


Hi all,

I'm a bit struggling to understand a KeyError raised by the multiprocessing library.

My idea is pretty simple. I want to create a server that will spawn a number of
workers that will share the same socket and handle requests independently.  The
goal is to build a 3-tier structure where all requests are handled via an http
server and then dispatched to nodes sitting in a cluster and from nodes to
workers via the multiprocessing managers...

There is one public server, one node per machine and x number of workers on
each machine depending on the number of cores... I know I can use a more
sophisticated library, but for such a simple task (I'm just prototyping here) I
would just use the multiprocessing library... Is this possible or I should
explore directly other solutions ? I feel I'm very close to have something
working here ...

The problem with the code below is that if I run the server as 
`python server.py 1` , that is, using only one process, it works as expected.

However if I spawn two processes (`python server.py 2`) listening for 
connections, I get a nasty error :

    $python client.py ping
    Traceback (most recent call last):
      File "client.py", line 24, in <module>
    sys.exit(main(sys.argv))
      File "client.py", line 21, in main
        print m.solver(args[1])._getvalue()
      File "/usr/lib/python2.6/multiprocessing/managers.py", line 637, in temp
        authkey=self._authkey, exposed=exp
      File "/usr/lib/python2.6/multiprocessing/managers.py", line 894, in AutoProxy
        incref=incref)
      File "/usr/lib/python2.6/multiprocessing/managers.py", line 700, in __init__
        self._incref()
      File "/usr/lib/python2.6/multiprocessing/managers.py", line 750, in _incref
        dispatch(conn, None, 'incref', (self._id,))
      File "/usr/lib/python2.6/multiprocessing/managers.py", line 79, in dispatch
        raise convert_to_error(kind, result)
    multiprocessing.managers.RemoteError: 
    ---------------------------------------------------------------------------
    Traceback (most recent call last):
      File "/usr/lib/python2.6/multiprocessing/managers.py", line 181, in handle_request
        result = func(c, *args, **kwds)
      File "/usr/lib/python2.6/multiprocessing/managers.py", line 402, in incref
        self.id_to_refcount[ident] += 1
    KeyError: '7fb51084c518'
    ---------------------------------------------------------------------------

My understanding is that all processes share the same socket (from the
Manager). When a client wants to connect, a new connection is created and
server independently by that process. If you look at the server trace (using
logging), it actually receives the connection, handles it, but fails to
communicate back to the client. 

Can anybody shed some light for me and maybe propose a solution ?

thanks 
pietro 

----------------------------------------

Server :

    import sys
    from multiprocessing.managers import BaseManager, BaseProxy, Process

    def baz(aa) :
        l = []
        for i in range(3) :
          l.append(aa)
        return l

    class SolverManager(BaseManager): pass

    class MyProxy(BaseProxy): pass

    manager = SolverManager(address=('127.0.0.1', 50000), authkey='mpm')
    manager.register('solver', callable=baz, proxytype=MyProxy)

    def serve_forever(server):
        try :
            server.serve_forever()
        except KeyboardInterrupt:
            pass

    def runpool(n):
        server = manager.get_server()
        workers = []

        for i in range(int(n)):
            Process(target=serve_forever, args=(server,)).start()

    if __name__ == '__main__':
        runpool(sys.argv[1])


Client :

    import sys
    from multiprocessing.managers import BaseManager, BaseProxy

    import multiprocessing, logging

    class SolverManager(BaseManager): pass

    class MyProxy(BaseProxy): pass

    def main(args) :
        SolverManager.register('solver')
        m = SolverManager(address=('127.0.0.1', 50000), authkey='mpm')
        m.connect()

        print m.solver(args[1])._getvalue()

    if __name__ == '__main__':
        sys.exit(main(sys.argv))


also tried on stack overflow and the python list, but I didn't manage to come up
with a working solution yet...

-- 
----
http://en.wikipedia.org/wiki/Posting_style

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


Thread

Problem with multiprocessing Pietro Abate <Pietro.Abate@pps.jussieu.fr> - 2011-05-19 15:10 +0200

csiph-web