Python Redundant Data Storage Module
Project description
RDS
Python Redundant Data Storage Module. Store changes made to a dictionary onto the disk in a redundant manor that will prevent it from getting corrupted if the saving is interrupted.
An RDSDict allows you to make asynchronous and multithreaded modifications to a dictionary safely, and also allows you to have those modifications saved in a way that is redundant. Should the object get interrupted during the saving process, it can restore from the most recently completed entry. An RDSList is the equivalent class for a list.
To create a new instance, each main RDS type takes two required arguments: location and name. location refers to folder where the RDS data will be saved and name refers to the name of the folder where the individual RDS data will be saved for this instance. While location can be shared. name must be unique.
from rds import RDSDict
myDict = RDSDict('C:/RDS/', 'myDict')
Once you have a new main instance, it can be used identically to the type that it is replacing. For example, RDSDict can directly replace a dict in any code, as long as the code does not specifically check if the instance is dict.
Creating a New RDS Type
This module will not be able to detect changes made to an object unless it has a corresponding RDS subtype. As such, if you want to use a custom type in an RDS structure and have changes to it registered, you will need to create your own RDS subtype. Doing so is a relatively simple process. The first thing you must do is create a new class that is a subclass of RDSSubBase.
from rds.rds_subtypes import RDSSubBase
class MyRDSSubType(RDSSubBase):
def __init__(self, master, instance):
RDSSubBase.__init__(self, master)
# Your code here...
You can make the mapping work however you would like, but you should make it so your custom RDS subtype is able to be used identically to the type it will be replacing. Any functions that will be modifying the object should be replaced by one that looks like this:
def myFunction(self, *args, **kwargs):
id = self._awaitTurn()
try:
# This is an example of how you could be calling your functions.
ret = self.__object.myFunction(*args, **kwargs)
except:
# Ensure that you remove the current id from the run list is an error has occured.
self._running.remove(id)
raise
try:
self._save()
finally:
# Ensure that you remove the current id from the run list.
self._running.remove(id)
return ret
If you need to do some custom procedure every time you save, you can implement your own save function that does that code before calling self._master._save(). Simply replace any calls to self._master._save() with that function instead.
You must also ensure that your subtype has a getData method that will either return the actual object being used or a copy of it. It is recommended to return a copy in some way so that you can use getData to get a copy of the object that is safe to modify. getData is a method that only takes the self argument.
Once you have done all of that, you will finally need to register your subtype with the module. So for a RDS subtype called MyRDSSubType that will be replacing objects of the class MyClass, you would register that like so:
registerRDSSubType(MyType, MyRDSSubType)
After that line has been executed, the module will be aware of your subtype and automatically replace any instances of the class you specified with the RDS subtype class.
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
Built Distribution
File details
Details for the file py-rds-1.3.0.tar.gz
.
File metadata
- Download URL: py-rds-1.3.0.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81a551bacae6f0985e3ae3dd7e6203f640038bd1c6cdead596453aaa4330cf25 |
|
MD5 | 8a79a1cd77c08f2bfc322e06e110e8de |
|
BLAKE2b-256 | a7849511be2ccd2a0ae022fcc91cc4600707c95cb248462e7fe423f4a98e637f |
File details
Details for the file py_rds-1.3.0-py3-none-any.whl
.
File metadata
- Download URL: py_rds-1.3.0-py3-none-any.whl
- Upload date:
- Size: 26.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4aa2946b4647f373298619e7b483d401c1d43af2740096d7c8dd0499a4dd454 |
|
MD5 | 9151fcc0d62905c2b6e04a076614b289 |
|
BLAKE2b-256 | 0374257197a90bbd7bce50952cf948205bea54394cecfda030cd93186bd94f26 |