Skip to main content

No project description provided

Project description

Rustex

Context Aware Async Mutex

Example

import asyncio
import random
import contextvars
import uuid

import rustex

mutex = rustex.Rustex()
cv = contextvars.ContextVar('rustex')


class PyRustexContext:
    def __init__(self):
        self.ctx = str(uuid.uuid4())

    def __enter__(self):
        cv.set(self.ctx)
        mutex.add_context(self.ctx)
        return self

    def __exit__(self, type, value, traceback):
        mutex.remove_context(self.ctx)
        cv.set(None)


class PyRustexMutex:
    def __init__(self, name: str):
        self.name = name

    async def __aenter__(self):
        await mutex.acquire_mutex(self.name, cv.get())
        return self

    async def __aexit__(self, type, value, traceback):
        await mutex.release_mutex(self.name, cv.get())


def with_rustex(name: str) -> PyRustexMutex:
    return PyRustexMutex(name)


async def a_main():
    async def drama(i):
        mt = 'test{}'.format(random.randint(0, 3))
        try:
            with PyRustexContext():
                async with with_rustex(mt):
                    print("In a_main in context {} on mtex {}".format(cv.get(), mt))
                    if random.random() < .5:
                        raise ArithmeticError("Dramatic Test Exception")
                    print("Survived mtex {}".format(mt))

        except ArithmeticError as e:
            print("Past exception mtex {}".format(mt))
            pass

    await asyncio.gather(*[drama(i) for i in range(10)])


def main():
    try:
        loop = asyncio.new_event_loop()
        loop.run_until_complete(a_main())
        loop.close()
    except Exception as e:
        print(e)


if __name__ == "__main__":
    main()

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

rustex-0.2.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

rustex-0.2.1-pp38-pypy38_pp73-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.3 MB view details)

Uploaded PyPymanylinux: glibc 2.12+ x86-64

rustex-0.2.1-pp37-pypy37_pp73-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.3 MB view details)

Uploaded PyPymanylinux: glibc 2.12+ x86-64

rustex-0.2.1-cp310-none-win_amd64.whl (297.8 kB view details)

Uploaded CPython 3.10Windows x86-64

rustex-0.2.1-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.12+ x86-64

rustex-0.2.1-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (868.3 kB view details)

Uploaded CPython 3.10macOS 10.9+ universal2 (ARM64, x86-64)macOS 10.9+ x86-64macOS 11.0+ ARM64

rustex-0.2.1-cp39-none-win_amd64.whl (298.0 kB view details)

Uploaded CPython 3.9Windows x86-64

rustex-0.2.1-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.12+ x86-64

rustex-0.2.1-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (868.6 kB view details)

Uploaded CPython 3.9macOS 10.9+ universal2 (ARM64, x86-64)macOS 10.9+ x86-64macOS 11.0+ ARM64

rustex-0.2.1-cp38-none-win_amd64.whl (298.4 kB view details)

Uploaded CPython 3.8Windows x86-64

rustex-0.2.1-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.12+ x86-64

rustex-0.2.1-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (868.3 kB view details)

Uploaded CPython 3.8macOS 10.9+ universal2 (ARM64, x86-64)macOS 10.9+ x86-64macOS 11.0+ ARM64

rustex-0.2.1-cp37-none-win_amd64.whl (298.4 kB view details)

Uploaded CPython 3.7Windows x86-64

rustex-0.2.1-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.12+ x86-64

rustex-0.2.1-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (868.3 kB view details)

Uploaded CPython 3.7mmacOS 10.9+ universal2 (ARM64, x86-64)macOS 10.9+ x86-64macOS 11.0+ ARM64

File details

Details for the file rustex-0.2.1.tar.gz.

File metadata

  • Download URL: rustex-0.2.1.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/0.13.2

File hashes

Hashes for rustex-0.2.1.tar.gz
Algorithm Hash digest
SHA256 c9bab25c77362ddcb1d5218d4fbfea893486fc5669f001022f6b9397cb121564
MD5 9c882291bc8af1fbc77c860b4353c97c
BLAKE2b-256 82ee9770899cb3c3cf251e3dfa576bde081e025b34eb7dbb9190eae42652dd3e

See more details on using hashes here.

File details

Details for the file rustex-0.2.1-pp38-pypy38_pp73-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for rustex-0.2.1-pp38-pypy38_pp73-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 e6d0daa5f814109f32bfebd07ddc4d1bda734ddbb5d37fb2d36cebf515c7d9d1
MD5 95a1bd4a051c4f67df55888330f6cd6f
BLAKE2b-256 c309731e314c60cdf7150743df936d7aa2522cb0b73def68c9dd7ba37dd00c9c

See more details on using hashes here.

File details

Details for the file rustex-0.2.1-pp37-pypy37_pp73-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for rustex-0.2.1-pp37-pypy37_pp73-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 909a58d874b58aa56375c10b97986cc636df3f9d5cea18f5f596023b0bce44c8
MD5 cb95440808e68b2e82c2909d92bf9c84
BLAKE2b-256 560efb9528dac137507ced0436af6e5a2182f97a78c385edbe60e2e89db4413f

See more details on using hashes here.

File details

Details for the file rustex-0.2.1-cp310-none-win_amd64.whl.

File metadata

  • Download URL: rustex-0.2.1-cp310-none-win_amd64.whl
  • Upload date:
  • Size: 297.8 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/0.13.2

File hashes

Hashes for rustex-0.2.1-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 022db42ba6b59260e56bdbd53093ceee9081bc2aeebf5ebe34a894d9efc7e0ab
MD5 d035bc95a452dc126921cb6b9f003c94
BLAKE2b-256 5b76f310944e2a45c55e570182bc2d7b805c0fabb49b90af1248ea4abddb5b1e

See more details on using hashes here.

File details

Details for the file rustex-0.2.1-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for rustex-0.2.1-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 3e2900ca46b5b8ae4ac73b29ddb0f2fa432a1e41ac1cb06e790b1211666c75a2
MD5 b63f1bf2b73910de107815f4768d3f8f
BLAKE2b-256 987784c5d07d90330adad01e646978f7f21e1283099d97c69c7134bf722c8398

See more details on using hashes here.

File details

Details for the file rustex-0.2.1-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for rustex-0.2.1-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 b3ebc89817729f9a18472469a15327e98adf0d95645ee849f65ed6602728961d
MD5 90ecb28252cc9b9638f1d3e408694a0f
BLAKE2b-256 4fabef0dcd697fa4fb9ff86256b5f0996ebf02617cbe4c77aef52ce42a50d71d

See more details on using hashes here.

File details

Details for the file rustex-0.2.1-cp39-none-win_amd64.whl.

File metadata

  • Download URL: rustex-0.2.1-cp39-none-win_amd64.whl
  • Upload date:
  • Size: 298.0 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/0.13.2

File hashes

Hashes for rustex-0.2.1-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 2be1850219a8809bf29b326f8f46835dd4f5dd3f5e93f9048f17bd8f49c57493
MD5 fd0d9167de4d23f82c58670e3bf682b6
BLAKE2b-256 88ff9ea183598f83e3ec7db6c88da1d5c57adbba05d764a03d7512d19b3fa947

See more details on using hashes here.

File details

Details for the file rustex-0.2.1-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for rustex-0.2.1-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 52d1dd3a3af8c4ad4cb8ee5e17bb4ed64d772229113d5a35a0fade7ab0137b86
MD5 e64f60e656feb8123434ae509c034965
BLAKE2b-256 16e12409ab251f268c9679014945a4e39d250ccd1e6a50f48925d2b2079abf24

See more details on using hashes here.

File details

Details for the file rustex-0.2.1-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for rustex-0.2.1-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 0a36d39873f3b63019b5cdaab787b3f189d73d5840d9e5c9421f750831a62b95
MD5 d10dc0295545ee7747a306d05e6a6dcb
BLAKE2b-256 5d0f19ceee9d7d42cc111ed00aa25232ae5780fe4129a0332acfe15520b268f9

See more details on using hashes here.

File details

Details for the file rustex-0.2.1-cp38-none-win_amd64.whl.

File metadata

  • Download URL: rustex-0.2.1-cp38-none-win_amd64.whl
  • Upload date:
  • Size: 298.4 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/0.13.2

File hashes

Hashes for rustex-0.2.1-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 e0248288a0e7d81dab2590c21a401bc7a9f536979c041b1d6ee392755440a50a
MD5 e64004ce9bfc6ad97084abab60769eae
BLAKE2b-256 8c2e22518fcab494540f534f403977104f40bd7505770eca49c3930a4b2175b8

See more details on using hashes here.

File details

Details for the file rustex-0.2.1-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for rustex-0.2.1-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 4b8e593faba91411a3ee3ba3005fcbed73647955d500b9ef7b196adda34fe05d
MD5 f4598cdc6b9d4ed02b8cc726c67b0ab8
BLAKE2b-256 9dd11dd10980fc7125dc979137cf3ff858bf4ae09d4e2fbc2bbdd2841f588dd1

See more details on using hashes here.

File details

Details for the file rustex-0.2.1-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for rustex-0.2.1-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 37182b0991925884f8e9a1a3ad11ba16d86cab1ff694ab0d540bdae34617edeb
MD5 8e2229ac06255ad459e8fe8e3420ead2
BLAKE2b-256 2c2a14e4bc87a39b6503f99f293a0a1ab5101f0fa7d73476af6fdfade7e03a15

See more details on using hashes here.

File details

Details for the file rustex-0.2.1-cp37-none-win_amd64.whl.

File metadata

  • Download URL: rustex-0.2.1-cp37-none-win_amd64.whl
  • Upload date:
  • Size: 298.4 kB
  • Tags: CPython 3.7, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/0.13.2

File hashes

Hashes for rustex-0.2.1-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 0096d8f886688c7cd36ed06b1982fa95077e2ecbe7aa9159d36888ae34738052
MD5 2c35f74537135a109b4df08a4cbce1b9
BLAKE2b-256 624f1649e9134b2e1d6d5dec3315c2ca66387a54712da781ddb44d701fb2fd2a

See more details on using hashes here.

File details

Details for the file rustex-0.2.1-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for rustex-0.2.1-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 cf0def62dee838c8da8da64625ff5cd2253ab48f5300fde5dc38c3dced4706f8
MD5 cd13e47e12f34688b1448c28328e73e8
BLAKE2b-256 f132b120d664e6149752035d78335c6db29a310c0698b5bbc25dc195b7444558

See more details on using hashes here.

File details

Details for the file rustex-0.2.1-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for rustex-0.2.1-cp37-cp37m-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 f6da822f94d6354a3650259b3f1dd55f08d2e06f963d56a343b2985df7eeac44
MD5 51c47345350a5b7758ea9094db24a417
BLAKE2b-256 b1d1f96120af95626d4fdcf47dac9ef43d2fa052cc287e6133b812909c7dc2cc

See more details on using hashes here.

Supported by

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