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


Groups > comp.lang.python > #25778

Re: A thread import problem

From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: A thread import problem
Date 2012-07-21 19:47 -0400
Organization > Bestiaria Support Staff <
References (1 earlier) <CA+WuaSeRExxaD9yCNWhXoWqsV_ZqP8DOvdErMRdNS-H_UtzQyg@mail.gmail.com> <87a9yt7bw6.fsf@handshake.de> <CA+WuaSc0Rm5s0CXsm7q7-gfyw+jQxpAGkuajpgFyoAHnTP12sQ@mail.gmail.com> <2u8m085co3j3n97jorkl04o5hr1orqb7la@invalid.netcom.com> <CA+WuaSde=GntxGMVTScOUw4_a+jqQS+nme0VpZVgH_219Qo9jA@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.2407.1342914432.4697.python-list@python.org> (permalink)

Show all headers | View raw


On Sat, 21 Jul 2012 17:10:05 -0600, Bruce Sherwood
<bruce.sherwood@gmail.com> declaimed the following in
gmane.comp.python.general:


> Thanks, but the problem I need to solve does not permit putting a
> function like runner in the main program. I'm constrained to being
> able to handle the API of VPython (vpython.org), which lets you write
> programs like the following (call it user.py), which animates a 3D
> cube moving to the right, using OpenGL:
> 
> from visual import box
> b = box()
> while True:
>     b.pos.x += 0.001

	Well, based on that sample, wrap THAT as "runner"

def runner():
	from visual import box
	b = box()
	while True:
		b.pos.x += 0.0001

and don't /call/ runner() until after all the main system is configured.
(And runner could, if need be, be "called" as a thread).

	Not having a Mac, I can't do tests... but everything I've seen so
far comes down to NOT IMPORTING anything that tries to spawn threads
/during the import/.

	A properly designed module (as I showed with my testABA.py) only
"runs" stuff if loaded as the main program; any other use (import) only
does imports and defines module level entities -- running anything is
deferred for the program that did the import to invoke AFTER the import
finished.
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

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


Thread

Re: A thread import problem Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-07-21 19:47 -0400

csiph-web