Distributed Computing with Python by Pierfederici Francesco
Author:Pierfederici, Francesco [Pierfederici, Francesco]
Language: eng
Format: azw3, mobi, epub
Publisher: Packt Publishing
Published: 2016-04-12T04:00:00+00:00
The pip command will install Pyro version 4.x as well as Serpent, the serializer that Pyro uses behind the scenes to encode and decode Python objects.
Rewriting the previous currency exchange rate application using Pyro will be only a tiny bit more complex than with Python-RQ, and it will involve one extra piece of software: the Pyro nameserver. We will, however, not need any broker or result backend as all Pyro objects will communicate directly with each other.
The high-level description of how Pyro works is as follows. Every object that we choose to access remotely is wrapped by the framework in a socket server listening for connections. Once some piece of code calls a method on one such remote object, the method call, together with its parameters, is serialized and sent over the wire to the appropriate object/server. At this point, the remote object performs whatever actions have been requested and sends the results back over the same connection (again, transparently serialized) to the calling code.
Since each remote object can itself call any other remote object, this architecture can be quite decentralized. In addition, once established, communication between objects is peer to peer, which is radically different from the loosely coupled architecture of distributed task queues. Another interesting aspect of Pyro applications is that each remote object can function as both a master and a worker.
Let's rewrite the currency exchange rate application using Pyro so that we can see how the code performs under a different architecture. Starting from the currency example, create a new Python script (pyro/worker.py) with the following code:
import urllib.request import Pyro4 URL = 'http://finance.yahoo.com/d/quotes.csv?s={}=X&f=p' @Pyro4.expose(instance_mode="percall") class Worker(object): def get_rate(self, pair, url_tmplt=URL): with urllib.request.urlopen(url_tmplt.format(pair)) as res: body = res.read() return (pair, float(body.strip())) # Create a Pyro daemon which will run our code. daemon = Pyro4.Daemon() uri = daemon.register(Worker) Pyro4.locateNS().register('MyWorker', uri) # Sit in an infinite loop accepting connections print('Accepting connections') try: daemon.requestLoop() except KeyboardInterrupt: daemon.shutdown() print('All done')
Download
Distributed Computing with Python by Pierfederici Francesco.mobi
Distributed Computing with Python by Pierfederici Francesco.epub
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Hello! Python by Anthony Briggs(9913)
The Mikado Method by Ola Ellnestam Daniel Brolund(9777)
Dependency Injection in .NET by Mark Seemann(9337)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7778)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7557)
Svelte with Test-Driven Development by Daniel Irvine(7135)
Test-Driven Development with PHP 8 by Rainier Sarabia(6862)
Layered Design for Ruby on Rails Applications by Dementyev Vladimir;(6728)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(6532)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6409)
Web Development with Django by Ben Shaw Saurabh Badhwar(6197)
React Application Architecture for Production by Alan Alickovic(5921)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(5806)
Kotlin in Action by Dmitry Jemerov(5062)
Audition by Ryu Murakami(4583)
Software Architecture for Web Developers by Mihaela Roxana Ghidersa(4439)
Hands-On Full-Stack Web Development with GraphQL and React by Sebastian Grebe(4316)
Accelerating Server-Side Development with Fastify by Manuel Spigolon Maksim Sinik & Matteo Collina(4286)
Functional Programming in JavaScript by Mantyla Dan(4037)
