Hi there,
I need to create an atomic section in Python code i.e. there is no
context switch to any other thread during the running of that piece of
code. Would would do the trick?
thanks, 6 5438
Ahmad Humayun wrote:
I need to create an atomic section in Python code i.e. there is no
context switch to any other thread during the running of that piece of
code. Would would do the trick?
use a lock, and make sure that anyone that needs access to the shared
state you're manipulating in that section uses the same lock.
lock = threading.Lock() # or RLock() etc [1]
with lock:
section
this only works if everyone honors the lock, of course; there's no way
in Python to lock out non-cooperating external threads.
</F>
1) see http://effbot.org/zone/thread-synchronization.htm
On Sep 5, 1:59*pm, Fredrik Lundh <fred...@pythonware.comwrote:
Ahmad Humayun wrote:
I need to create an atomic section in Python code i.e. there is no
context switch to any other thread during the running of that piece of
code. Would would do the trick?
use a lock, and make sure that anyone that needs access to the shared
state you're manipulating in that section uses the same lock.
* * *lock = threading.Lock() # or RLock() etc [1]
* * *with lock:
* * * * *section
this only works if everyone honors the lock, of course; there's no way
in Python to lock out non-cooperating external threads.
</F>
1) seehttp://effbot.org/zone/thread-synchronization.htm
Thats true, but this will ensure mutual exclusion; not atomicity
thanks again,
Ahmad Humayun schrieb:
On Sep 5, 1:59 pm, Fredrik Lundh <fred...@pythonware.comwrote:
>Ahmad Humayun wrote:
>>I need to create an atomic section in Python code i.e. there is no context switch to any other thread during the running of that piece of code. Would would do the trick?
use a lock, and make sure that anyone that needs access to the shared state you're manipulating in that section uses the same lock.
lock = threading.Lock() # or RLock() etc [1]
with lock: section
this only works if everyone honors the lock, of course; there's no way in Python to lock out non-cooperating external threads.
</F>
1) seehttp://effbot.org/zone/thread-synchronization.htm
Thats true, but this will ensure mutual exclusion; not atomicity
AFAIC that kind of mutual exclusion is what atomicity is about. What
else do you expect to happen?
Diez
On Sep 5, 10:59*am, Fredrik Lundh <fred...@pythonware.comwrote:
>
1) seehttp://effbot.org/zone/thread-synchronization.htm
The page you link here is WAYS better than the standard documentation
of the threading module.
Generally speaking, the effbot zone contains a lot of improvements
over the standard docs
which are lacking in various areas.
I have always wondered why they are kept separated. Wouldn't be nice
to have the standard
docs integrated with the effbot docs? Are there plans in this sense
and if not, why not?
Michele Simionato
Michele Simionato wrote:
The page you link here is WAYS better than the standard documentation
of the threading module.
Generally speaking, the effbot zone contains a lot of improvements
over the standard docs which are lacking in various areas.
I have always wondered why they are kept separated. Wouldn't be nice
to have the standard
docs integrated with the effbot docs? Are there plans in this sense
and if not, why not?
There are tons of great supplementary material out there, on blogs,
personal documentation collections (such as effbot.org), cookbook sites,
etc. I don't think all that material absolutely must be posted to
python.org, but Python users would definitely benefit from improved
cross-linking.
And this is, of course, something I've lobbied for many times, e.g. http://mail.python.org/pipermail/pyt...ay/322224.html http://mail.python.org/pipermail/pyt...er/355625.html http://effbot.org/zone/idea-seealso.htm
but I haven't yet figured out how to get something to happen [1]. All
ideas are welcome.
</F>
1) Well, I guess the new Sphinx tool might have gotten some inspiration
by my work in this domain: http://mail.python.org/pipermail/pyt...ry/059978.html
and Andrew Kuchling did some preliminary work for the old Latex work flow: http://svn.python.org/view/sandbox/trunk/seealso/
Diez B. Roggisch wrote:
AFAIC that kind of mutual exclusion is what atomicity is about. What
else do you expect to happen?
sounds like he wants/needs non-cooperative, mandatory locking.
</F> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Paul Moore |
last post by:
I can't find anything which spells this out in the manuals. I guess
that, at some level, the answer is "a single bytecode operation", but
I'm not sure that explains it for me.
This thought was...
|
by: Glenn Kasten |
last post by:
I am wondering which operations in Python
are guaranteed to be atomic in the presence
of multi-threading. In particular, are assignment
and reading of a dictionary entry atomic?
For example,...
|
by: Shayan |
last post by:
Is there a boolean flag that can be set atomically without needing to
wrap it in a mutex? This flag will be checked constantly by multiple
threads so I don't really want to deal with the overhead...
|
by: Pegboy |
last post by:
What does it mean to make a function atomic?
Something I read on it wasn't very clear, but made me think that I needed to
disable interrupts for that function. Whether that's the case or not,...
|
by: blackstreetcat |
last post by:
consider this code :
int i; //gobal var
Thread1:
i=some value;
Thread2:
if (i==2) dosomething();
else dosomethingelse();
|
by: Ole Nielsby |
last post by:
I need to implement reference counting in a class hierarch,
in a thread safe manner. (The classes are umanaged but I
might want to compile them with the /clr option.)
Some of the objects - atoms...
|
by: Ark |
last post by:
Consider
static T foo;
..............
T get_foo(void) { return foo; }
In a multi-threaded (or -tasked) environment, I need to ensure that I
get_foo() grabs T atomically (e.g. is not...
|
by: Dave Stallard |
last post by:
Pardon if this is the wrong newsgroup for this question, and/or if this
question is naive.
I have a multi-threaded Windows application in which certain
variables/object fields are shared: one...
|
by: Freedom fighter |
last post by:
Hello,
Is a singleton class the same as an atomic class? I know that a singleton class
can only be instantiated once, but does that concept apply to an atomic class?
Thank you.
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |