X
X
xozzslip2016-09-25 15:26:34
css
xozzslip, 2016-09-25 15:26:34

How to implement a resource lock for all threads except one?

There is a resource: access_token for vk api. If more than one thread sends a request with this access_token, then the server will return an error about too many requests per second, so you need to organize synchronous use of this resource.
There are some mutex that one-to-one solve my problem, but I still don’t understand how to write my own such mutex. Everywhere they give some examples of use, but I don’t understand how to implement the central acquire and release methods. I would like to go deeper into this

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Andrey Verkh, 2016-09-18
@VoxelGod

For main container with white background:
For nested arrow:
transform:skewX(-20deg)

D
Daemon23RUS, 2016-09-25
@xozzslip

first acquire the use of the token, and once the use is complete, release
And so on for each thread that uses the token.
The 1st thread that executes the acquire will lock the token and immediately continue execution. All parallel requests will stop at acquire (it will not return until the 1st thread calls release) when the object is released (release) in one of the parallel threads, acquire will return and the thread will continue execution. The remaining threads will remain waiting for acquire to return until release is called again. Thus, the resource (your token) will be divided.

O
Oleg Tsilyurik, 2016-09-25
@Olej

And you don’t need to implement anything, you need to take and use ready-made synchronization primitives ... from the thread or threading modules.
See for example: Python: examples and tests, part 4 - threads
PS But just keep in mind that in Python everything related to threads is very arbitrary, and there cannot be real parallelism (due to global locking).
For a detailed discussion, see here: Python - Python
Parallelism The finer points of using the Python language: Part 4. Para...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question