GithubHelp home page GithubHelp logo

marcoaaguiar / erised Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 32 KB

This is light-weight library to work to put objects in a different Process and iteract with it asynchronously.

License: MIT License

Python 100.00%

erised's Introduction

Erised: the magic mirror

This is light-weight library to work to put objects in a different Process and iteract with it asynchronously.

Example

This is a work in progress but herer it is a small snippet. Define some objects as usual

class Dog:
    def bark(self, loud: bool):
        sound = "woof-woof"
        if loud:
            return sound.upper()
        return sound


class Person:
    def __init__(self, dog: Dog = None):
        self.dog = dog

Create your objects and do wathever operations with it, when you want to send it to another Process create a proxy for it

person = Person()
person.dog = Dog()

proxy = Proxy(obj=person)

Now you can call the methods of the proxy like normal. Just remember that all operations on proxies return a Future object, similar to concurrent.futures.Future. To obtain the the result use .result() in the future object.

call_future = proxy.dog.bark(loud=True)
print(call_future.result())  # WOOF-WOOF

Attributes can be set into the remote object by setting the attribute in the proxy object. Setting attributes works even if it was not defined originally.

proxy.dog.age = 3

It's also possible to retrieve attributes from the remote object by including a .retrieve() at the end of a proxy. .retrieve() was purposely chosen to avoid name conflict with the underlying object.

get_future = proxy.dog.age.retrieve()
print(get_future.result())  # 3

Since an process was created, make sure to terminate the process by calling .terminate() on the proxy object.

proxy.terminate()

Debugging

To facilitate debugging you can create a local proxy by passing local=True to the proxy object.

proxy = Proxy(obj=person, local=True)

Notice that in local mode, when you you execute a .result() in a Future object, it will run all previous pending tasks from that proxy. Task are not executed on creation/request. For instance:

proxy = Proxy(obj=person, local=True)

call_future = proxy.dog.bark(loud=True)  # the method is not called yet

print(call_future.result())  # the method is called here -> WOOF-WOOF

You don't need to call proxy.terminate() on local proxies, but it is encouraged because it makes sure that all pending tasks are finished.

erised's People

Contributors

marcoaaguiar avatar

Watchers

James Cloos avatar  avatar

erised's Issues

Test Connector class

With the addition of these tests, we can ensure solid confidence in the package.

Documentation

The external API is minimal, but still, we should provide some documentation.

Parts:

  • Installation
  • Getting Started
  • All operations
  • Contributing

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.