Skip to content

Commit

Permalink
Merge pull request #21 from soda480/0.1.4
Browse files Browse the repository at this point in the history
Add code example
  • Loading branch information
soda480 authored Dec 8, 2020
2 parents a8b5214 + 39eb2ba commit 0165dbc
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 27 deletions.
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

Mpcurses is an abstraction of the Python curses and multiprocessing libraries providing function execution and runtime visualization capabilities at scale. It contains a simple API to enable any Python function to be executed across one or more background processes and includes built-in directives to visualize the functions execution on a terminal screen.

The mpcurses API allows for a seamless integration of the target function since it does not require any additonal context about curses or multiprocessing. The target function does need to implement logging since log messages are the primary means of inter-process communication between the background processes executing the function and the main process updating the curses screen on the terminal.
The mpcurses API allows for seamless integration since it does not require the target function to include additional context about curses or multiprocessing. The target function does need to implement logging since log messages are the primary means of inter-process communication between the background processes executing the function and the main process updating the curses screen on the terminal.

The main features are:

Expand All @@ -32,7 +32,7 @@ pip install mpcurses

### Examples ###

A simple example using mpcurses...
A simple example using mpcurses:

```python
from mpcurses import MPcurses
Expand Down Expand Up @@ -61,6 +61,36 @@ MPcurses(
Executing the code above results in the following:
![example](/docs/images/example.gif)

To scale execution of the function across multiple processes, we make a few simple updates:

```python
from mpcurses import MPcurses
import namegenerator, time, logging
logger = logging.getLogger(__name__)

def run(*args):
group = args[0].get('group', 0)
for _ in range(0, 600):
logger.debug(f'processing item "[{group}]: {namegenerator.gen()}"')
time.sleep(.01)

MPcurses(
function=run,
process_data=[{'group': 1}, {'group': 2}, {'group': 3}],
screen_layout={
'display_item': {
'position': (1, 1),
'color': 14,
'clear': True,
'regex': r'^processing item "(?P<value>.*)"$',
'table': True
}
}).execute()
```

Executing the code above results in the following:
![example](/docs/images/example-multi.gif)

Serveral [examples](/examples) are included to help introduce the mpcurses library. Note the functions contained in all the examples are Python functions that have no context about multiprocessing or curses, they simply perform a function on a given dataset. Mpcurses takes care of setting up the multiprocessing, configuring the curses screen and maintaining the thread-safe queues that are required for inter-process communication.

#### [example1](/examples/example1.py)
Expand Down
29 changes: 4 additions & 25 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,9 @@
# limitations under the License.

"""
The mpcurses provides a framework that enables a function to be executed at scale and its execution to be visualized on screen at runtime. It consists of a simple set of APIs that provide an abstraction for multiprocessing and the curses screen painting library. The main features:
* Execute a function across one or more concurrent processes
* Queue execution to ensure a predefined number of processes are running
* Visualize function execution using curses screen
* Define a screen layout using a Python dict
* Leverage built-in directives for dynamically updating the screen
* Keep numeric counts
* Update text values
* Update text colors
* Maintain visual indicators
* Update progress bars
* Display tables
The framework can be used on any ordinary Python function. The only requirement for enabling function scale and execution visualization is to ensure the function implements logging and a to provide a screen layout definition. The framework takes care of setting up the multiprocessing, configuring the curses screen and the maintaining the thread-safe queues required for communication.
Refer to [How It Works](https://github.com/soda480/mpcurses/wiki/How-It-Works) for additional detail.
Refer to [API Reference](https://github.com/soda480/mpcurses/wiki/API-Reference) for description of the API methods and the screen layout directives.
For samples checkout our home page: https://github.com/soda480/mpcurses
Mpcurses is an abstraction of the Python curses and multiprocessing libraries providing function execution and runtime visualization capabilities at scale. It contains a simple API to enable any Python function to be executed across one or more background processes and includes built-in directives to visualize the functions execution on a terminal screen.
The mpcurses API allows for seamless integration since it does not require the target function to include additional context about curses or multiprocessing. The target function does need to implement logging since log messages are the primary means of inter-process communication between the background processes executing the function and the main process updating the curses screen on the terminal.
For examples checkout our home page: https://github.com/soda480/mpcurses
"""

from pybuilder.core import use_plugin
Expand All @@ -59,7 +38,7 @@
]
summary = 'A framework that exposes a simple set of APIs enabling multi-process integration with the curses screen painting library'
url = 'https://github.com/soda480/mpcurses'
version = '0.1.3'
version = '0.1.4'
default_task = [
'clean',
'analyze',
Expand Down
Binary file added docs/images/example-multi.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/example.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/example1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/example2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/example3.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0165dbc

Please sign in to comment.