Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
TinyDb with Pythonista - anyone played with this?
-
All joking aside, that's my problem. What is reported is so wrong.it stalls. Talking about 3 to 5 seconds. It's not the tenths of seconds reported. That's why i am lost. The only code outside timing from what I can see is import datetime
-
What gets printed out when you run https://github.com/Phuket2/Pythonista/blob/master/tinydb_timer.py ?
-
@ccc , I got the following
Elapsed time (import json): 0:00:00.000015
Elapsed time (import tinydb): 0:00:00.000044
Elapsed time (TinyDbWrapper()): 0:00:00.005246
Total time: 0:00:00.048388I had my friend on my iphone, with the stopwatch. The stop watch 4.06sec
-
Was there a 4 second delay BEFORE the first text was printed?
-
@ccc , no the first text is always displayed immediately.but after that it changes. I know it does not make sense. But that is what is happening. Look, I don't mean to waste your time. If I had to guess there is something in the db that I saved is causing the problem.
Just what I don't get is why I can not capture the timing where the hold up is. Seems crazy -
What if you put some time.sleep(), what do you get?
what about printing just the datetime objects to see if they look right? maybe print as you go to ensure tinydb is not mangling them.
-
@JonB , not exactly sure what you meant about time.sleep. I did the below. But the manual timing is 3 or 4 seconds longer than what is reported. I did it carefully on my iphone with a friend.
import time import contextlib, datetime script_start = datetime.datetime.now() @contextlib.contextmanager def timer(name='timer'): start = datetime.datetime.now() yield print('Elapsed time ({}): {}'.format(name, datetime.datetime.now() - start)) with timer('import json'): import json with timer('import tinydb'): from tinydb import TinyDB, Query class TinyDbWrapper(object): def __init__(self, db_name, purge = False): self.db = TinyDB(db_name) if purge: self.db.purge() if __name__ == '__main__': with timer('TinyDbWrapper()'): sleep_time = 4 print 'sleeping {}'.format(sleep_time) time.sleep(sleep_time) tdb = TinyDbWrapper('elf.json') print('Total time: {}'.format(datetime.datetime.now() - script_start)) print 'finished'
-
My iphone on my ipad…
-
@Phuket2
Whereever you have a datetime.now, also print out the datetimeobj immediately. That might give you both a visual and numeric indication of where the problem lies.Is this in python 2 or 3?
-
also, i guess for completeness, your start_time should be before the contextlib imports, though it is hard to imagine that taking 3 seconds, especially after running twice.
-
try using cProfile.run instead of the timer method. The timer might have some "whitespace" that this is falling through.
-
@JonB , thanks for all the feedback. Getting late here now. I have some crazy guys visiting me tomorrow for 4 days. I will try all you suggest as soon as I get a chance. I want to get to the bottom of it if I can.