Giter Site home page Giter Site logo

pombredanne / dualprocessing Goto Github PK

View Code? Open in Web Editor NEW

This project forked from michaelosthege/dualprocessing

0.0 1.0 0.0 21 KB

This module is designed to help with running a single-instance, thread-blocking computation pipeline on a second process. It does all the heavy lifting of scheduling calls and asynchronously waiting for the results.

License: MIT License

Python 100.00%

dualprocessing's Introduction

Summary

This module is designed to help with running a single-instance, thread-blocking computation pipeline on a second process. It does all the heavy lifting of scheduling calls and asynchronously waiting for the results.

Scenario

The primary use case is running of a webservice that executes blocking calls sequentially on a second process. Handlers of the webservice will remain asynchronous, therefore many requests can be accepted in parallel. Some typical constraints include:

  • you want to accepts many requests in parallel
  • backend calls are slow (fine for the client, but unacceptable for the server)
  • backend calls are blocking
  • backend calls return picklable values
  • backend calls are first-in-first-out
  • there exists only one instance of the backend thing that is called
  • all calls must happen on the same thread/process
  • thing import and instance creation is slow (common for deep learning frameworks)

Solution

A Broker is created that runs a user-provided constructor on a new thread to create one instance of the Processor (thing).

A pipe connection between the Broker (first process) and the Processor (second process) is used to transfer calls and their results.

Each call is indentified by a unique key. When a it comes in, it is passed through the pipe to the backend computation process. The loop at the other end of the pipe sequentially does the (blocking) calls, while the main thread asynchronously waits for the response to be returned through the pipe.

For an example of a webservice using the dualprocessing module, take a look here.

Installation

The package is indexed on Pypi, so you can install it via pip:

pip install dualprocessing

dualprocessing's People

Contributors

michaelosthege avatar

Watchers

 avatar

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.