Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #96862 > unrolled thread

Re: Local variables and thread safety

Started bydieter <dieter@handshake.de>
First post2015-09-20 08:02 +0200
Last post2015-09-20 08:02 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Local variables and thread safety dieter <dieter@handshake.de> - 2015-09-20 08:02 +0200

#96862 — Re: Local variables and thread safety

Fromdieter <dieter@handshake.de>
Date2015-09-20 08:02 +0200
SubjectRe: Local variables and thread safety
Message-ID<mailman.31.1442728965.21674.python-list@python.org>
Saint Desmond <st.kooday@gmail.com> writes:

> Dear Team,
> Kindly advise if variables declared within a function are thread safe.

In general, yes. However, there are exceptions.

First of all, "variable" is not the optimal term to use in this context.
In Python, a "variable" is nothing more than the binding of a name
to an object. The local binding in a function itself is thread safe; however,
operations on the bound object may not be thread safe.

For example, if the bound object comes from outside the function
(i.e. it is visible outside the function) then other threads could
modify it and those modifications conflict with each other or
modifications in this thread.

Another example would be the use of a locally defined function
(wich can access "variable"s defined in the enclosing function) as
a thread.


Look at Python's "threading" module to find general purpose utilities
to assure thread safety.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web