Skip to main content

cgroupy is a python module that provides a simple intrface for managing cgroups

Project description

cgroupy

cgroupy is a python module that provides a simple interface for managing cgroups

Installation

You can install cgroupy using pip:

pip install cgroupy

Usage

cgroupy impelemets a cgroup object. This object can be used to both create a new cgroup, and to interact with an existing one. When you initialize a cgroup object, you cand specify the CPU and memory limits you wish to set. Memory is specified in megabytes, and CPU limits are specified in CPU shares/megahertz.

Once a cgroup object is initialized, you can check if it exists, create it if it does not, run processes inside it, and destroy it like so:

>>> from cgroupy import cgroup
>>> c = cgroup('test', memory=1000, cpu=1000)
>>> c.exists
False
>>> c.setup()
>>> c.exists
True
>>> process = c.execute('echo hello world')
>>> print(process.communicate())
(b'hello world\n', b'')
>>> c.teardown()
>>> c.exists
False

IN addition to the cgroup.execute method that lets you run an arbitrary command inside of your cgroup, you can add a running PID to the cgroup, or launch new processes from python and add them:

>>> from cgroupy import cgroup
>>> import multiprocessing
>>> import time
>>> def test():
...   time.sleep(150)
... 
>>> c = cgroup('test')
>>> c.setup()
>>> p = multiprocessing.Process(target=test)
>>> p.start()
>>> c.add_pid(p.pid)
>>> c.add_pid(p.pid)
>>> c.tasks
{'17202'}
>>> p.pid
17202

with syntax is also supported for automated setup and teardown:

>>> with cgroup('test', memory=1000, cpu=500) as c:
...   c.execute('echo hello world')
 
(b'hello world\n', b'')

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

cgroupy-0.0.7.tar.gz (3.4 kB view details)

Uploaded Source

File details

Details for the file cgroupy-0.0.7.tar.gz.

File metadata

  • Download URL: cgroupy-0.0.7.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.13

File hashes

Hashes for cgroupy-0.0.7.tar.gz
Algorithm Hash digest
SHA256 29ef0fb50fe1d5613ef42762bfa41ba8e97d5fd0d01702086346625e7f4778b1
MD5 e0d20ccfd2a47846ffe067a9a62e4c75
BLAKE2b-256 ee8d0aae17d2d2d2cb4ce786d11699de9c88ea5e9a27f7e59cb43908c94cea30

See more details on using hashes here.

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