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


Groups > comp.lang.python > #96862

Re: Local variables and thread safety

Path csiph.com!goblin2!goblin1!goblin.stu.neva.ru!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.008
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'python,': 0.02; 'modify': 0.04; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'thread': 0.10; 'variables': 0.15; 'exceptions.': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'thread.': 0.16; 'threads': 0.16; 'team,': 0.18; 'all,': 0.20; 'context.': 0.22; 'object.': 0.22; 'visible': 0.22; 'defined': 0.23; "python's": 0.23; 'module': 0.25; 'header:User-Agent:1': 0.26; 'example': 0.26; 'header:X-Complaints-To:1': 0.26; 'function': 0.28; 'declared': 0.29; 'operations': 0.31; 'another': 0.32; 'could': 0.35; 'there': 0.36; '(i.e.': 0.36; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'charset:us-ascii': 0.37; 'itself': 0.38; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'term': 0.60; 'more': 0.63; 'kindly': 0.64; 'within': 0.64; 'binding': 0.66; 'received:217': 0.66; 'dear': 0.67; 'function)': 0.84; 'safe;': 0.84; 'safety.': 0.84; 'saint': 0.84; 'safe.': 0.93
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From dieter <dieter@handshake.de>
Subject Re: Local variables and thread safety
Date Sun, 20 Sep 2015 08:02:34 +0200
References <E6D0DE73-37C9-41BF-89A6-8553D4A1430E@gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Gmane-NNTP-Posting-Host pd9e0a988.dip0.t-ipconnect.de
User-Agent Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux)
Cancel-Lock sha1:aExiS2PQ9enwjpy+Lvxy28kkR0k=
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.31.1442728965.21674.python-list@python.org> (permalink)
Lines 25
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1442728965 news.xs4all.nl 23851 [2001:888:2000:d::a6]:44542
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:96862

Show key headers only | View raw


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.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web