Skip to main content

cleanroom

Install:

pip install cleanroom

Create instance in a new process and proxy all operations:

import os
import time
from cleanroom import create_instance, CleanroomArgs


class Cal:

    def __init__(self, base):
        self.base = base

    def inc(self):
        self.base += 1
        return self.base

    def pid(self, sleep=None):
        if sleep:
            time.sleep(sleep)

        return os.getpid()


cal = create_instance(Cal, CleanroomArgs(0))

print('Parent PID: ', os.getpid())
print('Cal PID: ', cal.pid())

print('inc: ', cal.inc())
print('inc: ', cal.inc())

Output:

Parent PID:  22239
Cal PID:  22272
inc:  1
inc:  2

Create multiple instances under the random_access scheduler:

from cleanroom import create_scheduler, create_instances_under_scheduler


scheduler = create_scheduler(instances=5, scheduler_type='random_access')
create_instances_under_scheduler(scheduler, Cal, CleanroomArgs(0))

print('Parent PID: ', os.getpid())

for _ in range(20):
    pid = scheduler.pid(sleep=1)
    print(time.ctime(), 'Cal PID:', pid)

Output:

Parent PID:  4376
Thu May 23 14:00:59 2019 Cal PID: 4399
Thu May 23 14:01:00 2019 Cal PID: 4403
Thu May 23 14:01:01 2019 Cal PID: 4397
Thu May 23 14:01:02 2019 Cal PID: 4397
Thu May 23 14:01:03 2019 Cal PID: 4403
Thu May 23 14:01:04 2019 Cal PID: 4399
Thu May 23 14:01:05 2019 Cal PID: 4395
Thu May 23 14:01:06 2019 Cal PID: 4401
Thu May 23 14:01:07 2019 Cal PID: 4399
Thu May 23 14:01:08 2019 Cal PID: 4395
Thu May 23 14:01:09 2019 Cal PID: 4401
Thu May 23 14:01:10 2019 Cal PID: 4401
Thu May 23 14:01:11 2019 Cal PID: 4403
Thu May 23 14:01:12 2019 Cal PID: 4395
Thu May 23 14:01:13 2019 Cal PID: 4397
Thu May 23 14:01:14 2019 Cal PID: 4403
Thu May 23 14:01:15 2019 Cal PID: 4401
Thu May 23 14:01:16 2019 Cal PID: 4395
Thu May 23 14:01:17 2019 Cal PID: 4395
Thu May 23 14:01:18 2019 Cal PID: 4397

Create multiple instances under the batch_random_access scheduler:

scheduler = create_scheduler(instances=5, scheduler_type='batch_random_access')
create_instances_under_scheduler(scheduler, Cal, CleanroomArgs(0))

print('Parent PID: ', os.getpid())

for pid in scheduler.pid(CleanroomArgs(sleep=1) for _ in range(20)):
    print(time.ctime(), 'Cal PID:', pid)

Output:

Parent PID:  4376
Thu May 23 14:04:47 2019 Cal PID: 4429
Thu May 23 14:04:47 2019 Cal PID: 4433
Thu May 23 14:04:47 2019 Cal PID: 4435
Thu May 23 14:04:48 2019 Cal PID: 4433
Thu May 23 14:04:48 2019 Cal PID: 4437
Thu May 23 14:04:49 2019 Cal PID: 4429
Thu May 23 14:04:49 2019 Cal PID: 4433
Thu May 23 14:04:49 2019 Cal PID: 4437
Thu May 23 14:04:49 2019 Cal PID: 4431
Thu May 23 14:04:49 2019 Cal PID: 4435
Thu May 23 14:04:50 2019 Cal PID: 4429
Thu May 23 14:04:51 2019 Cal PID: 4431
Thu May 23 14:04:51 2019 Cal PID: 4435
Thu May 23 14:04:51 2019 Cal PID: 4431
Thu May 23 14:04:51 2019 Cal PID: 4437
Thu May 23 14:04:53 2019 Cal PID: 4429
Thu May 23 14:04:53 2019 Cal PID: 4431
Thu May 23 14:04:53 2019 Cal PID: 4429
Thu May 23 14:04:53 2019 Cal PID: 4437
Thu May 23 14:04:53 2019 Cal PID: 4437

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

0.1.0 (2019-05-10)

  • First release on PyPI.

Metadata

Release files for cleanroom 0.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cleanroom 0.4.2
File Size Uploaded
cleanroom-0.4.2.tar.gz 13.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cleanroom 0.4.2
File Interpreter ABI Platform
cleanroom-0.4.2-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 20.5 kB

Release files / cleanroom-0.4.2.tar.gz

Download URL cleanroom-0.4.2.tar.gz
Size 13.6 kB
Tags Source
SHA-256 checksum
How to use checksums
38bd1bf3e4c4fd82ecb514f694e671e3a1494c33ca81c2ae3668df5cfafdaa88
BLAKE2b-256 checksum
How to use checksums
d524e524f25f75870426a9a9f197d2bdb81445fce1ec450bd9e636e312f9d726
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.3

Release files / cleanroom-0.4.2-py2.py3-none-any.whl

Download URL cleanroom-0.4.2-py2.py3-none-any.whl
Size 6.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
238a63f7a25e99262f3157c9aeaab366278f90f7b38d65dfb822fd9bc5612259
BLAKE2b-256 checksum
How to use checksums
6f190930ebac1d440911b67d520fe016d4407868d7d8430c9326bf413ec229ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.3

Release history Release notifications | RSS feed

This release

0.4.2 This release

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page