Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin1!goblin.stu.neva.ru!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; 'python.': 0.02; 'python,': 0.02; 'api.': 0.04; 'modified': 0.05; '"__main__":': 0.07; '64-bit': 0.07; '__name__': 0.07; 'executable': 0.07; 'wrapped': 0.07; 'api': 0.09; 'python': 0.09; '"if': 0.09; '(those': 0.09; '22,': 0.09; 'app,': 0.09; 'logic': 0.09; 'oh,': 0.09; 'prevents': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'spawn': 0.09; 'specifying': 0.09; 'thread,': 0.09; 'programs.': 0.11; 'thread': 0.11; 'library': 0.15; '"import': 0.16; 'absolute,': 0.16; 'animations,': 0.16; 'bring.': 0.16; 'cocoa,': 0.16; 'conflicting': 0.16; 'existence,': 0.16; 'function).': 0.16; 'headaches': 0.16; 'hypothetical': 0.16; 'out"': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'rewritten': 0.16; 'subject:import': 0.16; 'thread.': 0.16; 'uses,': 0.16; 'vpython': 0.16; 'which,': 0.16; 'later': 0.16; 'wrote:': 0.17; 'liable': 0.17; 'saying': 0.18; 'appears': 0.18; 'module': 0.19; 'trying': 0.21; 'import': 0.21; 'parse': 0.22; 'subject:problem': 0.22; 'programming': 0.23; 'absolute': 0.23; 'bruce': 0.23; "i've": 0.23; 'allows': 0.25; 'coding': 0.27; 'prevent': 0.27; '(as': 0.27; 'convention': 0.27; 'header:X -Complaints-To:1': 0.28; 'run': 0.28; 'cocoa': 0.29; 'enforce': 0.29; 'far,': 0.29; 'invoke': 0.29; 'physics,': 0.29; 'statements': 0.29; 'style.': 0.29; 'usable': 0.29; 'wrap': 0.29; 'url:mailman': 0.29; 'definition': 0.29; 'source': 0.29; "i'm": 0.29; 'maybe': 0.29; 'function': 0.30; 'primary': 0.30; 'code': 0.31; 'problem.': 0.32; 'url:python': 0.32; 'file': 0.32; '(2)': 0.32; 'mac': 0.32; 'structure': 0.32; 'running': 0.32; 'could': 0.32; 'url:listinfo': 0.32; '5000': 0.33; 'real-time': 0.33; 'url:home': 0.33; 'problem': 0.33; 'to:addr:python-list': 0.33; 'another': 0.33; 'requirements': 0.33; 'version': 0.34; "can't": 0.34; 'project': 0.34; '(1)': 0.34; 'architecture': 0.34; 'wrong': 0.34; 'exist': 0.35; 'especially': 0.35; 'doing': 0.35; 'pm,': 0.35; 'continue': 0.35; 'something': 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'url:org': 0.36; 'apple': 0.36; 'modules': 0.36; 'programmers': 0.36; 'anything': 0.36; 'should': 0.36; 'charset:us-ascii': 0.36; 'turn': 0.36; 'supporting': 0.37; 'does': 0.37; 'level': 0.37; 'two': 0.37; 'being': 0.37; 'subject:: ': 0.38; 'perform': 0.38; 'some': 0.38; 'things': 0.38; 'nothing': 0.38; 'more': 0.63; 'behavior': 0.64; 'jul': 0.65; 'dangerous': 0.66; 'manner.': 0.66; 'direct': 0.69; 'teach': 0.69; 'college': 0.71; 'hand': 0.82; "'if": 0.84; 'forced': 0.84; 'viable': 0.84; 'wrapper,': 0.84; 'dennis': 0.91; 'novice': 0.91; 'instructors': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: A thread import problem Date: Sun, 22 Jul 2012 23:40:10 -0400 Organization: > Bestiaria Support Staff < References: <87a9yt7bw6.fsf@handshake.de> <2u8m085co3j3n97jorkl04o5hr1orqb7la@invalid.netcom.com> <5gfm08htgbrum782hfv5fqkb4084qra7vq@invalid.netcom.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-76-249-26-210.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 3.3/32.846 X-No-Archive: YES 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: 92 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1343014811 news.xs4all.nl 6875 [2001:888:2000:d::a6]:47826 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:25837 On Sun, 22 Jul 2012 17:14:28 -0600, Bruce Sherwood declaimed the following in gmane.comp.python.general: > On Sun, Jul 22, 2012 at 3:48 PM, Dennis Lee Bieber > wrote: > > On Sun, 22 Jul 2012 13:04:25 -0600, Bruce Sherwood > > declaimed the following in > > gmane.comp.python.general: > > > > > >> Another way of saying this is that I'm not building an app, in which > >> case I would structure things in a simple and straightforward manner. > >> I am instead trying to maintain and update a library that allows > >> novice programmers to write programs that generate real-time navigable > >> 3D animations, writing minimalist programs that work cross-platform. > >> > > I suspect you don't need to update the library so much as enforce a > > project style that prevents your import-thread-import cycle. In short, > > something like that hypothetical "runner()" design. > > > > Oh, and document that style in detail: "importable modules shall > > only perform module level definition of entities during import -- no > > code that actually processes data"; "importable modules shall make use > > of the 'if __name__ == "__main__": main()' convention to identify when > > the module is being used stand-alone, and thereby invoke the main > > processing; otherwise the module.main() function is to be invoked only > > be the module doing the imports, after the import has completed" > > etc. > > > > -- > > Wulfraed Dennis Lee Bieber AF6VN > > wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/ > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > There's nothing wrong with the current VPython architecture, which > does use good style, but there are two absolute, conflicting > requirements that I have to meet. > > (1) The simple program API I've shown must be preserved, because there > exist a large number of such programs in existence, used by lots of > people. I can't change the API. Among other uses, every semester there > are about 5000 students in introductory college science courses, > especially physics, who do computational modeling with 3D > visualizations based on instructional materials that teach the > existing API. There is also a large number of instructors who depend > on existing VPython demo programs to continue working even if the > college upgrades Python and VPython. This isn't some little project > where I'm able to teach my small group of collaborators how they > should structure programs. > > (2) My hand is forced by Apple no longer supporting Carbon. Among > other aspects of this, Carbon can't be used with 64-bit Python, and > more and more Mac users of VPython want to use 64-bit Python. So there > has to be a version of VPython that is based on Cocoa, but Cocoa is > required to be the primary thread. This requirement, combined with the > absolute requirement that the VPython API cannot be changed, is the > problem I face. I have to turn the architecture inside out, > independent of whether the solution meets all criteria for good Python > programming style. > As has been shown -- anything that spawns a thread during an import is liable to cause a problem. The only viable solution that I've been able to see is to ensure that any existing program is tweaked to make it "import safe" -- which, so far, appears to be using the "if __name__..." scheme to prevent running dangerous logic during an import. Using this scheme does not change the program behavior when used stand-alone (as they currently exist); but does make them viable when wrapped for your "inside out" architecture (import, THEN spawn the main process as a thread, or maybe even just run it as a direct function). For NEW programs (those generated by your "...novice programmers to write programs..."), specifying a coding style to use "if __name__..." would make new programs usable without the headaches existing programs bring. I see NO viable means to have an outside program magically be able to load/execute one of these existing programs unless it is able to parse the source file and wrap the dangerous executable statements into a function for later calling after the import. And if you can write such a wrapper, you could have it edit all the programs to use the "if __name__ ..." scheme in a batch, and then generate a modified main program to import/start the rewritten program. -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/