threading.Thread wrapper with convenient functions
Project description
why?
i just can’t be bothered to write the same boilerplate code over and over again. so i wrote it into a little library. it has the ‘android’ lifecycle in mind:
on_start (before the loop gets called)
work (in the loop)
on_stop (when the loop has finished)
also it has a useful function called ‘stop’
how to…
… install
pip3 install git+https://github.com/smthnspcl/pyrunnable
… use it
from runnable import Runnable
from time import sleep
class ThreadedObject(Runnable):
def __init__(self, **kwargs): # not necessary but included for the sake of completeness
Runnable.__init__(self, **kwargs) # gotta super to Runnable as you would with Thread
def on_start(self):
print("we are going to run in a loop")
def work(self):
print("working")
sleep(0.42) # be nice to the cpu
def on_stop(self):
print("we finished working. time for beer")
o = ThreadedObject()
try:
o.start()
o.join() # Runnable inherits threading.Thread
except KeyboardInterrupt:
o.stop()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyrunnable-0.42.tar.gz
(2.2 kB
view hashes)
Built Distributions
pyrunnable-0.42-py3.8.egg
(3.2 kB
view hashes)
Close
Hashes for pyrunnable-0.42-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6b2576e03ef27e39e94053db02e22ebc521227ee3950d7dd533a9b2d0b72df3 |
|
MD5 | 771c887aef391be701310f9811eb228b |
|
BLAKE2b-256 | 401b8d9db078226eb46e84bc1abe8a9b491fefe0fe8db9a24161016857f591c7 |