Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to implement your own locking for all shared variables that will be modified in Python. You don't have to worry about reading from the variables that won't be modified (ie, concurrent reads are ok), so immutable types (<code>frozenset</code>, <code>tuple</code>, <code>str</code>) are <em>probably</em> safe, but it wouldn't hurt. For things you're going to be changing - <code>list</code>, <code>set</code>, <code>dict</code>, and most other objects, you should have your own locking mechanism (while in-place operations are ok on most of these, threads can lead to super-nasty bugs - you might as well implement locking, it's pretty easy).</p> <p>By the way, I don't know if you know this, but locking is very easy in Python - create a threading.lock object, and then you can acquire/release it like this:</p> <pre><code>import threading list1Lock = threading.Lock() with list1Lock: # change or read from the list here # continue doing other stuff (the lock is released when you leave the with block) </code></pre> <p>In Python 2.5, do <code>from __future__ import with_statement</code>; Python 2.4 and before don't have this, so you'll want to put the acquire()/release() calls in <code>try:...finally:</code> blocks:</p> <pre><code>import threading list1Lock = threading.Lock() try: list1Lock.acquire() # change or read from the list here finally: list1Lock.release() # continue doing other stuff (the lock is released when you leave the with block) </code></pre> <p><a href="http://effbot.org/zone/thread-synchronization.htm" rel="noreferrer">Some very good information about thread synchronization in Python</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload