Skip to main content

A bunch tools I have created over the years

Project description

Slurm

Actions Status GitHub PyPI - Python Version PyPI PyPI - Downloads

This is a collection of tools I have used over the years collected together.

Signal Catcher

SignalCatch catches SIGINT and SIGTERM signals and sets SignalCatch.kill to True.

from slurm import SignalCatch

sig = SignalCatch()

while True:
    if sig.kill == True:
        exit(0)

Simple Processes

from slurm import SimpleProcess

def func():
    # some simple process that does something
    for _ in range(10):
        print(".", end="")
        time.sleep(0.1)
    print("")

def test_process():
    p = SimpleProcess()
    p.start(func)
    print(p)
    p.join(timeout=2.0) # if not ended in 2 sec, will terminate() the process

Storage

from slurm import storage

pick = storage.read("file.pickle")
yaml = storage.read("file.yaml")
json = storage.read("file.json")
json = storage.read("file", "json")


data = [1,2,3,4]
storage.write("tom.pickle", data)
storage.write("bob.json", data)
storage.write("guess.file", data, "yml")

Also, for YAML files, you can put comments in:

info = {
    "a": 1
}

num = 5
comm = f"""
# hello {num} dogs!!
# there
# big boy
"""
storage.write("t.yaml", info, comments=comm)

which will produce:

# hello 5 dogs!!
# there
# big boy

a: 1

Science Storage

Over the years I have collected a lot of data, but not completely documented the sensors or their settings. I am trying to setup a data file that can:

  • use primarly standard python libraries to read (exception dill for namedtuples)
  • self documenting with info and namedtuples
  • can use gzip for compression of large files
from slurm import scistorage
from collections import namedtuple

Sensor = namedtuple("Sensor","x y z")

# document sensor setting in this data file
info = {
    "TFmini": {
        "min": 0.3,
        "max": 12.0,
        "fov_deg": 4.6,
        "units": "m"
    },
    "LSM6DSOX": {
        "accel": {
            "range": (-4,4),
            "units": "g"
        },
        "gyro": {
            "range": (-2000,2000),
            "units": "dps"
        }
    },
    "LIS3MDL": {
        "range": (-4,4), # 4 gauss = 400 uT
        "units": "gauss"
    },
    "DPS310": {
        "sensors": ("temperature", "pressure")
    }
}

data = [] # some data stored in an array or deque
for i in range(100):
    data.append(Sensor(i,i,i)) # pretend you got some data from a sensor


scistorage.write(info, data, "data.dil.gz") # *.gz uses gzip compression

bag = scistorage.read("data.dil.gz")
print(bag["info"])
print(bag["data"])

Network

from slurm import network

print(network.get_ip()) # -> ip_address
print(network.host()) # -> (hostname, ip_address)

Sleep Rate

Will sleep for a prescribed amount of time inside of a loop irregardless of how long the loop takes

from slurm import Rate

rate = Rate(10)  # let loop run at 10 Hz

while True:
    # do some processing
    rate.sleep()

Files

from slurm.files import rmdir, mkdir, run, rm, find

mkdir("some/path")
rmdir("some/path")
rm("/path/file.txt")
rm(["path/a.txt", "path/2/b.txt", "path/3/c.txt"])

find("/path/to/somewhere", "file_to_find") # -> list
find("/path/to/somewhere", "*.html") # -> list

run("ls -alh") # -> output

MIT License

Copyright (c) 2014 Kevin J. Walchko

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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

slurm-0.5.0.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

slurm-0.5.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file slurm-0.5.0.tar.gz.

File metadata

  • Download URL: slurm-0.5.0.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.9.6 Darwin/21.1.0

File hashes

Hashes for slurm-0.5.0.tar.gz
Algorithm Hash digest
SHA256 b040ce0f4567b432d29918e8122d44837237ce3c3e936aa7b7f382c1bec107fc
MD5 576a7397ddedd5b1f5403a9e6bcebbbc
BLAKE2b-256 ad78c3226cc152418593fae3effdb20101ce9a2b5a6115916f4834632653025b

See more details on using hashes here.

File details

Details for the file slurm-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: slurm-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.9.6 Darwin/21.1.0

File hashes

Hashes for slurm-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 64ec98b308122d50602c96e9f45cca271ca3b9d11f70645991291c89fbc537b3
MD5 eec937640e45230e1b0aed9dd8254726
BLAKE2b-256 fba09dc7650e72344484e8e2dfe43015ecaf83f2760f60195e7f7d993f4d8333

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