Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autocommit does not commit if program exits #93

Closed
endlisnis opened this issue Mar 23, 2019 · 13 comments · Fixed by #94
Closed

autocommit does not commit if program exits #93

endlisnis opened this issue Mar 23, 2019 · 13 comments · Fixed by #94
Assignees
Labels

Comments

@endlisnis
Copy link
Contributor

I ran into a problem in one of my programs where it was not committing some changes because my script exited shortly after the updates.

Here is a example script that reliably reproduces the effect (for me):

import json
import sqlitedict
import time

class Dict(sqlitedict.SqliteDict):
    def __init__(self, name):
        sqlitedict.SqliteDict.__init__(
            self,
            f'{name}.sqlite', autocommit=True,
            encode=json.dumps, decode=json.loads )

d = Dict('d')
now = int(time.time())

for i in range(100):
    d[i] = now

If I follow that up with a select, I only see 18 entries (sometimes I see zero entries):

$ sqlite3 d.sqlite 'SELECT * from unnamed'
0|1553346705
1|1553346705
2|1553346705
3|1553346705
4|1553346705
5|1553346705
6|1553346705
7|1553346705
8|1553346705
9|1553346705
10|1553346705
11|1553346705
12|1553346705
13|1553346705
14|1553346705
15|1553346705
16|1553346705
17|1553346705
18|1553346705
@endlisnis endlisnis changed the title autocommit not guaranteed if program exits autocommit does not commit if program exits Mar 23, 2019
@piskvorky
Copy link
Owner

You're right. If the program exits, all internal threads / queues are discarded by Python/OS, at indeterminate time.

I'm not sure what we could do about it on our end… @mpenkov maybe make some operations (like commit) blocking, instead of using background threads and queues?

@piskvorky piskvorky added the bug label Mar 23, 2019
@endlisnis
Copy link
Contributor Author

I thought commit was blocking already. This comment implies it's blocking: #52 (comment)

@piskvorky
Copy link
Owner

A commit should definitely be blocking IMO. If true, I consider this a bug. Thanks for reporting.

I'm not sure when I'll get to fixing this -- please feel free to suggest a PR.

@endlisnis
Copy link
Contributor Author

"commit" is blocking, but "autocommit" is not. I think this would be as simple as calling "commit" as part of setitem, if "autocommit" is True.

@piskvorky
Copy link
Owner

OK, go for it! PR welcome.

@endlisnis
Copy link
Contributor Author

My PR fixes the problem for me. Is there anything more I need to do?

@endlisnis
Copy link
Contributor Author

Is there anything more I can do to assist in getting this fix merged?

@endlisnis
Copy link
Contributor Author

I see this issue is closed, but the most recent released version of this project is from 2018. Are there any plans on doing another release soon? It would be nice to be able to use auto-commit from the official released version.

@piskvorky
Copy link
Owner

@mpenkov WDYT?

@mpenkov
Copy link
Collaborator

mpenkov commented Sep 3, 2020

Yes, I will do a new release tomorrow.

@mpenkov
Copy link
Collaborator

mpenkov commented Sep 10, 2020

Forgot to post the URL to the new version here: https://pypi.org/project/sqlitedict/1.7.0/

@endlisnis
Copy link
Contributor Author

Forgot to post the URL to the new version here: https://pypi.org/project/sqlitedict/1.7.0/

Great. That seems to work (including with pip), so that satisfies my technical requirements, but it is NOT listed as the "latest release" on github. 1.6.0 is still listed as the "latest" release.

@mpenkov
Copy link
Collaborator

mpenkov commented Sep 10, 2020

Thank you for pointing that out. Should be fixed now: https://github.com/RaRe-Technologies/sqlitedict/releases/tag/1.7.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants