On 08Aug2022 11:20, Stefan Ram <[email protected]> wrote:
>Andreas Croci <[email protected]> writes:
>>Basically the question boils down to wether it is possible to have parts
>>of a program (could be functions) that keep doing their job while other
>>parts do something else on the same data, and what is the best way to do
>>this.
>
> Yes, but this is difficult. If you ask this question here,
> you might not be ready for this.
This is a very standard requirement for any concurrent activity and the
typical approach is a mutex (mutual exclusion). You've already hit on
the "standard" approach: a `threading.Lock` object.
> lock.acquire()
> try:
> list.append( i )
> finally:
> lock.release()
Small note, which makes writing this much clearer. Lock objects are
context managers. So:
with lock:
list.append(i)
is all you need.
Cheers,
Cameron Simpson <[email protected]>
--
https://mail.python.org/mailman/listinfo/python-list