Python Forum
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dictionary is empty
#1
I'm writing my own CRUD (more like URD) database -- for fun and possible production environment as I've needed a database which fits the requirements this one does for years.

PPDF: NoSQL Database

The code has default settings and also takes a settings.json file to customize things as needed. My settings.json file is (the codes reading it fine):

{
	"db_path": "__mem__",
	"mem_max": 500
}
The __mem__ setting tells the DB to store all entries in memory only and the mem_max tells the DB maximum permissible size of memory-based storage. When the DB exceeds said storage limit, the first entry is to be popped from the tickets variable (which is where memory is stored or variables wait to be written to disk in a non-memory-based DB).

You can use the shell script to populate the DB with information:

PUSH {"username":{"password":"something cool"}}

At 500 bytes, it shouldn't take but a few seconds to fill with random info -- the first 200 are already done for you.

At the moment -- for troubleshooting -- I have the DB set up to print the size of the tickets variable every second.

When I push information to the database, the tickets var size increases but when it reaches the designated max value and I try to pop the first variable, I get this error:

Error:
Exception in thread Thread-1: Traceback (most recent call last): File "C:\Users\mary\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 916, in _bootstrap_inner self.run() File "C:\Users\mary\AppData\Local\Programs\Python\Python36-32\lib\threading.py", line 864, in run self._target(*self._args, **self._kwargs) File "E:\PPDF\ppdf.py", line 89, in memMaxThread tickets.popitem() KeyError: 'dictionary is empty'
Again, I was expecting it to just pop the first ticket. I considered that maybe it was a matter of scope but then, why would the function be able to access tickets to get the size?

Sorry if there's an edit button but I couldn't find it. On further examination of my output:
This was the numerical output. I added one new entry after it said 460 (to push it over 500. As you can see, I succeeded and it starts popping entries but never goes below 500).

Output:
PPDF V18.05.29 IS RUNNING ======================================== PORT: 5044 200 200 200 200 200 200 200 200 216 216 216 216 216 216 216 216 232 232 232 232 232 232 232 232 232 232 232 232 232 232 248 248 248 248 248 248 248 248 248 264 264 264 264 280 280 280 280 280 396 396 412 412 412 428 428 428 428 444 444 444 444 460 460 460 688 672 656 640 624 608 592 576 560 544 528 512
Reply
#2
After asking on Quora about how much data I could put into a dictionary, I was linked here: https://www.laurentluce.com/posts/python...mentation/

When deleting a key from a Python dictionary, the dictionary entry remains a dummy entry until the number of dummy entries is deemed excessive by Python or another entry is added to the dictionary.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Empty attribute class dictionary after saving it in a class object dictionary 3dimensions 6 4,855 May-20-2018, 01:57 PM
Last Post: 3dimensions

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020