Skip to content
Snippets Groups Projects
Commit c20123bc authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

recipes removed

parent 425db0d5
No related branches found
No related tags found
No related merge requests found
......@@ -16,7 +16,6 @@ Welcome to satella's documentation!
exception_handling
json
posix
recipes
Indices and tables
......
# Recipes
How to do common things.
## Check if running as root
**__This can run only on POSIX. This will raise ImportError on non-POSIX platforms, such as MS Windows__**
```python
from satella.posix import is_running_as_root
if is_running_as_root():
print('Root!')
else:
print('Not root')
```
## Acquire a PID lock file
**__This can run only on POSIX. This will raise ImportError on non-POSIX platforms, such as MS Windows__**
Use a context manager, _AcquirePIDLock_ from module _satella.pid_. Example:
Example:
```python
from satella.posix import AcquirePIDLock
with AcquirePIDLock('satella.pid'):
print('Lock is acquired!')
print('Now lock is acquired!')
```
_AcquirePIDLock_ accepts extra keyword parameters:
* base_dir (default _/var/run_) - base directory of PID lock files
* delete_on_dead (default False) - if lock exists, but it's holder is dead,
remove the lock file and retry.
Entering _AcquirePIDLock_ context may throw:
* _AcquirePIDLock.FailedToAcquire_ - base class for errors. Thrown if can't read the file
* _AcquirePIDLock.LockIsHeld_ - lock is already held. This has two attributes - pid (int), the PID of holder,
and is_alive (bool) - whether the holder is an alive process
It is safe (and advisable!) to fork() inside this context manager.
Writing to _/var/run_ may require root permissions.
# coding=UTF-8
__version__ = '2.2.2a2'
__version__ = '2.2.2a3'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment