Closed GoogleCodeExporter closed 9 years ago
Reproduced on WinXP Py2.5 speech 0.5.2
Original comment by gundl...@gmail.com
on 2 Mar 2009 at 1:19
The partial diagnosis of the bug: Python is unhappy when you do "real work"
during
module import (stuff beyond defining classes and functions.). I've seen this
with
the paramiko ssh package: if module a.py tries to connect to a remote client,
and
b.py imports a, then the ssh will hang.
I'm not sure what "real work" entails -- starting threads? using COM objects?
opening
raw sockets? -- so I don't know the true root cause of the problem.
The workaround is to have start.py define a method "main()", in which it does
its
"real work"; then have the other python script do
import start
start.main()
Let me know if this does not work.
Original comment by gundl...@gmail.com
on 2 Mar 2009 at 1:46
Thank you for your reply;
I'm very new to Python (I've always been the web application guy) so how do I
define
a main() method?
Thanks. :)
Original comment by nathan...@xyteran.com
on 2 Mar 2009 at 11:33
Pardon me! You've been a regular commenter here so I assumed you were quite
deep
into the guts of Python :)
You define a function (I called it a method above erroneously) called 'foo'
like this:
def foo():
your stuff here
So, start.py would look something like:
import speech
# defining functions is fine
def callback(phrase, listener):
# do something
def main():
# actually running speech functions is not fine, so put its use in a function
# to be called later. I named mine main(), as lots of people tend to do.
listener = speech.listenfor(['howdy', 'partner'], callback)
import time
time.sleep(60) # sixty seconds to handle 'howdy' and 'partner' over and over
and other.py (perhaps 'main.py' or __init__.py) looks like:
import start
start.main() # run the stuff that you *wanted* to run via plain import
Good luck!
Michael
Original comment by gundl...@gmail.com
on 3 Mar 2009 at 1:26
Oh, just a function? I know how to do that, haha. :P Thanks!
Original comment by nathan...@xyteran.com
on 3 Mar 2009 at 2:15
Original issue reported on code.google.com by
nathan...@xyteran.com
on 20 Feb 2009 at 2:34