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


Groups > comp.lang.python > #25613

Re: A thread import problem

Path csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!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.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'context': 0.05; 'modified': 0.05; 'source.': 0.05; 'exec': 0.07; 'function,': 0.07; 'performs': 0.07; 'python': 0.09; 'imported': 0.09; 'imports': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'runs,': 0.09; 'thread,': 0.09; 'thread': 0.11; 'source,': 0.15; 'illustrates': 0.16; 'invokes': 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; 'subject:import': 0.16; 'thread.': 0.16; 'vpython': 0.16; 'later': 0.16; 'fix': 0.17; '(in': 0.18; 'module': 0.19; 'discussion': 0.20; 'math': 0.20; 'versions': 0.20; 'suggested': 0.20; 'trying': 0.21; 'import': 0.21; 'displayed': 0.22; 'subject:problem': 0.22; 'runs': 0.22; 'work,': 0.22; 'bruce': 0.23; 'statement': 0.23; "i've": 0.23; 'tried': 0.25; 'header:User-Agent:1': 0.26; 'environment.': 0.27; "doesn't": 0.28; 'header:X-Complaints-To:1': 0.28; 'run': 0.28; 'environment': 0.29; '(possibly': 0.29; 'cocoa': 0.29; 'context,': 0.29; 'locking': 0.29; 'loop,': 0.29; 'writes:': 0.29; 'case,': 0.29; 'starts': 0.29; 'source': 0.29; "i'm": 0.29; 'error': 0.30; 'primary': 0.30; 'problem.': 0.32; 'mac': 0.32; 'message.': 0.33; 'comments': 0.33; 'function.': 0.33; 'to:addr:python-list': 0.33; 'program,': 0.34; 'list': 0.35; 'something': 0.35; 'there': 0.35; 'received:org': 0.36; 'created': 0.36; 'but': 0.36; 'test': 0.36; 'should': 0.36; 'charset:us- ascii': 0.36; 'turn': 0.36; 'uses': 0.37; 'rather': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'instead': 0.39; 'to:addr:python.org': 0.39; 'easily': 0.39; 'header:Received:5': 0.40; 'below,': 0.60; 'side': 0.61; 'kind': 0.61; 'mentioned': 0.63; 'respect': 0.63; 'success': 0.63; 'making': 0.64; 'received:217': 0.68; 'saw': 0.75; 'altered)': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dieter Maurer <dieter@handshake.de>
Subject Re: A thread import problem
Date Thu, 19 Jul 2012 10:31:11 +0200
References <CA+WuaScBDU_5LcrCrTtDr6N3gHCk9hQ03fA=DT359GCRY=a=KQ@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Gmane-NNTP-Posting-Host pd9e09232.dip0.t-ipconnect.de
User-Agent Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux)
Cancel-Lock sha1:P2LYHAbmTWX0zknzmE00hp2W7vg=
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2293.1342686687.4697.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1342686687 news.xs4all.nl 6939 [2001:888:2000:d::a6]:41704
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:25613

Show key headers only | View raw


Bruce Sherwood <bruce.sherwood@gmail.com> writes:

> I'm trying to do something rather tricky, in which a program imports a
> module that starts a thread that exec's a (possibly altered) copy of
> the source in the original program, and the module doesn't return.
> This has to do with an attempt to run VPython in the Mac Cocoa
> context, in which Cocoa is required to be the primary thread, making
> it necessary to turn the environment inside out, as currently VPython
> invokes the Carbon context as a secondary thread.
>
> I've created a simple test case, displayed below, that illustrates
> something I don't understand. The module reads the source of the
> program that imported it, comments out the import statement in that
> source, and performs an exec of the modified source. The module then
> enters an infinite loop, so that there is no return to the original
> program; only the exec-ed program runs, and it runs in a secondary
> thread.
>
> The puzzle is that if there is any later import statement in the exec
> source, the exec program halts on that import statement, with no error
> message. I saw a discussion that suggested a need for the statement
> "global math" to make the math import work, but that doesn't fix the
> problem. I've tried with no success various versions of the exec
> statement, with respect to its global and local environment.

In a recent discussion in this list someone mentioned that
on module import, you should not start a thread. The reason: apparently,
Python uses some kind of locking during import which can interfere
with "import"s in the started thread.

You can (in principle) easily avoid starting the thread on module import.
Instead of starting the thread as a side effect of the import,
put the start in a function, import the module and then call
the thread starting function.

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


Thread

Re: A thread import problem Dieter Maurer <dieter@handshake.de> - 2012-07-19 10:31 +0200

csiph-web