K
K
kommov2017-09-15 01:50:39
Python
kommov, 2017-09-15 01:50:39

What is the best way to implement multithreading to SQLite through python (and not only)?

I am not strong in databases, so this problem arose. sqlite contains approximately 500k rows. 1k threads access random strings, change one parameter, and take other strings. it is necessary to somehow separate the threads so that the same string is not used by other threads. I know that MySQL has SELECT FOR UPDATE, which automatically blocks access of other threads. i.e., for example, you can take the necessary data with the "0" parameter, change it to "1", and these lines will no longer be taken by other threads, or do nothing at all. Is there something similar for SQlite? I know, you can also write queues in python, but it's too complicated for me. can anyone help?)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Astrohas, 2017-09-15
@Astrohas

SELECT ... FOR UPDATE OF ... is not supported in SQLite. This is understandable given that row locking is redundant in SQLite, since the entire database is already locked when any bit of it is updated.

A
Alexander Kuznetsov, 2017-09-15
@DarkRaven

There was an article about it on habrahabr - https://habrahabr.ru/post/149635/
With regards to multithreading - https://www.quantstart.com/articles/parallelising-...
In general, you can do it in different ways. The easiest option:
Add a marker (column) "Processed" to the record and an index on it.
Then, randomly pull a record from the database ( https://ruhighload.com/post/%D0%9E%D0%BF%D1%82%D0%... ) and start processing.
Launch in general. You can read random strings in "packs" (finish the query above, but at least unions), 10 pieces, for example, and start parallel processing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question