Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'importing': 0.04; 'sys': 0.05; '21,': 0.07; 'append': 0.07; 'works.': 0.07; 'callback': 0.09; 'called.': 0.09; 'explicitely': 0.09; 'imported': 0.09; 'imports': 0.09; 'received:mail-vb0-f46.google.com': 0.09; 'gui': 0.11; 'thread': 0.11; 'sat,': 0.15; 'diagnostic': 0.16; 'folder.': 0.16; 'modules,': 0.16; 'subject:import': 0.16; 'threads': 0.16; 'true:': 0.16; 'wrote:': 0.17; 'circular': 0.17; 'received:209.85.212.46': 0.18; 'math': 0.20; 'import': 0.21; 'subject:problem': 0.22; 'work.': 0.23; 'bruce': 0.23; 'originally': 0.23; 'sets': 0.23; 'statement': 0.23; 'this:': 0.23; 'tried': 0.25; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'received:209.85.212': 0.28; 'invoke': 0.29; 'sleep': 0.29; 'skip:_ 10': 0.29; "i'm": 0.29; "skip:' 10": 0.30; 'code': 0.31; 'file': 0.32; 'to:addr:python- list': 0.33; 'version': 0.34; 'skip:- 20': 0.34; 'received:google.com': 0.34; 'problem,': 0.35; 'doing': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'but': 0.36; 'visual': 0.36; 'test': 0.36; 'skip:p 20': 0.36; 'execute': 0.37; 'listing': 0.37; 'usual': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'little': 0.39; 'header:Received:5': 0.40; "you'll": 0.62; 'situation': 0.62; 'jul': 0.65; 'wrong!': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=snyrF7i0hrd1Ie5YyKwRnRZ9lBOitAtZ2BsL+RW6O0k=; b=cptbQdDGjNGobvIu+7Nj3mvMtKmFL2CDSS+dFCTT8UrA7i6zvaavaHqISGZAqOLd8S ZDKP+FuHZdtEu9DKzYEJh0vOFdehkNCYTvIsJC+yJhO9xS/sZlPKQIwAv+eDs1IvcTjC klVDEx8ncQkGyUWxmozXTKBvl3mvpM/P4U7kaYlyKnAgfz9cSR0mO0JWC7fhte8Lqi3m JlEBpwID6HPihj1EtSYbMsv/LLlacxrTLn+hUaDyvecfcESDjU8t/BvQlSdNXcE7Uibt la4lkdjw3epwcww7AsMSlBw8/HSj8LOf4fg9xuEqnFq56QLAYvW+4YudC+iFjMil8RHQ im0A== MIME-Version: 1.0 In-Reply-To: <87a9yt7bw6.fsf@handshake.de> References: <87a9yt7bw6.fsf@handshake.de> Date: Sat, 21 Jul 2012 10:11:30 -0600 Subject: Re: A thread import problem From: Bruce Sherwood To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 59 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1342887093 news.xs4all.nl 6948 [2001:888:2000:d::a6]:57476 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25748 I couldn't get a simple test case to work. I append a listing of the little test files, all in the same folder. The diagnostic statement print('after start_new_thread\n') works, but then nothing. Originally I tried importing testABA.py but was worried that the circular importing (A imports B which imports A) would be a problem, hence the test of importing a version of the test program without the import. The failure of this test case suggests that one cannot do imports inside secondary threads started in imported modules, something I keep tripping over. But I hope you'll be able to tell me that I'm doing something wrong! Incidentally, a simple test is to execute the file ABA.py, in which case everything works. Bruce Sherwood --------------------------- testABA.py -- execute this file from ABA import * print('exec testABA') from math import sin print(sin(3.14159/6)) ---------------------------- testABA_noimport.py -- a version of testABA.py without the import of ABA print('exec testABA_noimport') from math import sin print(sin(3.14159/6)) ----------------------------- ABA.py from thread import start_new_thread from time import sleep import sys user = 'testABA_noimport' start_new_thread(lambda: __import__(user), ()) print('after start_new_thread\n') while True: sleep(1) On Sat, Jul 21, 2012 at 2:32 AM, Dieter Maurer wrote: > The usual approach to this situation is to invoke the user code via > a callback from the UI main loop or invoke it explicitely > after the UI system has been set up immediately before its main loop > is called. Might look somehow like this: > > main thread: > > from thread import start_new_thread > from visual import setup_gui, start_main_loop > setup_gui() # sets up the GUI subsystem > start_new_thread(lambda: __import__(), ()) > start_main_loop()