Also os.name returns 'nt' on Win 98. How can I identify the correct OS
name if I need to take care of it in my program (to tell it not to use the
Thread class on Win 98 for example).
Thanks
Anand Pillai
Please post a short example that demonstrates the problem. These things
do work, and very reliably.
> Also os.name returns 'nt' on Win 98. How can I identify the correct OS
> name if I need to take care of it in my program (to tell it not to use the
> Thread class on Win 98 for example).
Generally this is a bad thing. You want to test for functionality,
not specific versions. That is, test whether the thing you want is
present, and catch an exception if it is not. Of course, this might
be hard in a case like you are describing, but luckily you will *not*
need to do it in this specific case.
Try this from the prompt if you are having trouble (warning, untested
code, but I type this stuff frequently so it "ought" to work):
import threading
class Task(threading.Thread):
def terminate(self):
self._terminate = 1
def run(self):
print 'starting'
import time
self._terminate = 0
while not self._terminate:
print 'working'
time.sleep(5)
print 'stopping'
>>> t = Task()
>>> t.start()
starting
>>> # now wait a few seconds to let the thread print its stuff
working
working
working
>>> # when you're done, do this to finish cleanly:
>>> t.terminate()
stopping
-Peter
> Does pyhton not support the 'threading' module in Windows 98. I find
> that the Thread class in the threading module does not work very well on
> Windows 98. Most of the time it does not call the thread target.
Hi Anand,
From what I've seen it works great on Win98. Please post some code.
-Dave
But my question is still valid, in another sense. The concerned
thread was calling a function for walking a directory and doing some
operation on the files. I found that the following line was causing
problems for the thread.
def ThreadFunc(self, event):
#...
currfile = os.path.abspath(self._fileName)
#operations on currfile...
Once I removed the call to os.path.abspath() the code runs fine in
the thread. The variable self._fileName in itself contains the file fullpath
. I had added the call to os.path.abspath to just make sure of it. I also
find that the code using this call works fine in the main thread.
Here is the whole code for your perusal;
<CODE>
#begin thread class
class pyWiewSlideThread(threading.Thread):
"""Thread subclass to perform slideshows"""
#This class is used to do a slideshow of images
def __init__(self, name, func, args):
threading.Thread.__init__(self, None, func, name)
#flag to stop slideshow (to be set from outside)
self._flag = 0
#function to call
self._func = func
#arguments for the function
self._args = args
#slideshow gap
self._gap = _options.ShowDuration()
#whether to loop slideshow
self._loop = _options.ShowLoop()
def run(self):
"Run the thread"
stindex=self._func(self._args)
time.sleep(self._gap)
index=0
while self._flag == 0:
index=self._func(self._args)
if self._loop == false:
if index == stindex:
break
time.sleep(self._gap)
#To untoggle the slideshow menuitem of caller
_frame.ToggleSlideMenu()
def SetFlag(self):
"To be called from outside to end thread"
print "Flagging thread..."
self._flag = 1
# end of thread class
#Begin thread func
def DirWalkDown(self,event,loop=0):
"Walk down a directory in alphabetical order and display images"
dir = self._dir
#causing problem with thread ?
currfile = os.path.abspath(self._fileName)
#locate the index of the current file in
#filelist
index = self._filelist.index(currfile)
#end of list
if index + 1 == len(self._filelist):
index = -1
#get the next file
self._fileName = self._filelist[index+1]
self.OpenImage(self._fileName)
return index
#End thread func
</CODE>
Thanks for your help and sorry for blaming python threads! :-)
Regards
Anand Pillai
Dave Brueck <da...@pythonapocrypha.com> wrote in message news:<mailman.104005076...@python.org>...