daemonise (class)¶
- class fundamentals.daemonise(log, name, **akws)[source][source]¶
Bases:
objectA class to daemonise a python code
Key Arguments:
log– loggername– a name for the daemon (e.g. python package name)
Usage:
Add something like this to your command-line usage:
```text Usage: myCommand (start|stop|restart|status)
- Options:
start start the myCommand daemon stop stop the myCommand daemon restart restart the myCommand daemon status print the staus of the myCommand daemon
and then when executing the commands:
```python from fundamental import daemonise class myDaemon(daemonise):
- def action(
self, **kwargs):
self.log.info(‘starting the
actionmethod’)anotherParameter = kwargs[“anotherParameter”]
import time while True:
print(f”OVERRIDE ACTION - {anotherParameter}”) time.sleep(3)
self.log.info(‘completed the
actionmethod’) return None
d = myDaemon(log=log, name=”gocart”, anotherParameter=42.)
- if a[‘start’]:
d.start()
- elif a[‘stop’]:
d.stop()
- elif a[‘restart’]:
d.restart()
- elif a[‘status’]:
d.status()
Replace **akws with any keywords you need.
Methods