Skip to main content

Client code for python Mona instrumentation

Project description

Python Client

Installation

$ pip install mona-client

Environment variables

Mona uses several environment variables you need to set in order for things to work as intended:

MONA_HOST - the Mona server's IP address you get from Mona. MONA_PORT - The port for the above address. MONA_USER_ID - A unique user id we provide for you.

Quick Start and Example

  • install as mentioned above
  • Set environment variables as mentioned above
  • Instrument code with client as seen below
from mona_client import client
...

with client.new_mona_context():
    ...
    client.export({"foo": "bar"})
    ...

Concurrency

Mona saves the ARC's id as a special variable, which is local to the thread and to greenlets. This means that if you start a new thread/greenlet, by default the new thread will have an empty context.

This is usually the preffered behavior, as a new thread usually means a new received request (on servers) or a completely new run of an algorithm.

If by any chance you'd like to continue with the same context on a new thread, just use the child class MonaThread under mona_thread.py. This class takes care of transferring the full context id to the newly started thread.

from mona_client import client
from mona_client.mona_thread import MonaThread

def threaded_function():
    print(client.get_full_context_id() == main_context)

with client.new_mona_context():
    global main_context
    main_context = client.get_full_context_id()
    MonaThread(target=threaded_function).start()  # Prints "True"

Testing the client code

The client's tests are written using the pytest framework, so in order to run the tests (assuming you have pytest installed on your environment), you just need to type "pytest" to your shell.

Uploading new version to PyPI

The main reference to follow to do that is on: https://packaging.python.org/tutorials/packaging-projects/

  • Register on PyPI with your mona email: https://pypi.org/
  • Ask itai@monalabs.io to add you as collaborator
  • If not installed, install twine: $ python3 -m pip install --user --upgrade twine
  • Change version number under setup.py
  • If a new dependency is required, add it under setup.py under "install_requires"
  • If not installed, install build tools: $ python3 -m pip install --user --upgrade setuptools wheel
  • Build new version: $ python3 setup.py sdist bdist_wheel
  • Upload new version (can change '*' to actual version): $ python -m twine upload dist/_

Configuration and Big Red Button

If you'd like to set up configuration for mona, you can fill a simple json configuration file. See mona_client_config.json for the default configuration file used. There is currently only one configuration option, which is the "Big Red Button" - the "disable_all" configuration, which, when set to true, completely disables all mona activity (no more exporting and context inits).

Mona listens to changes on the configuartion file under the environment variable "MONA_CLIENT_CONFIG_FILE". So if you want to disable mona while running, just change "disable_all" from "false" to "true" in your config file and mona will update automatically.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mona_client-0.1.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

mona_client-0.1.0-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file mona_client-0.1.0.tar.gz.

File metadata

  • Download URL: mona_client-0.1.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for mona_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cc80f51418d346896387d19ed5144e8447352f35c835c56649bc182268760402
MD5 796775e003be50e341a9d4dff5f3afb3
BLAKE2b-256 e714af1bf5927dac16654f40e30e92bee75562ba4a13b21844793ef3de1d0cc2

See more details on using hashes here.

Provenance

File details

Details for the file mona_client-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mona_client-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for mona_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2ae69c3e869328ca917152d7855ad5655233af871554df63d009b16ac596d733
MD5 4d9826b42e397d37973717d4bd0ee996
BLAKE2b-256 b813cab81d1a3920ec477dff797dc3126c23e14b5f96aaaaeabba7c603796fe5

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page