Win98 threads

Anand B Pillai abpillai at lycos.com
Tue Dec 17 01:26:07 EST 2002


Thanks for the replies and the code... Guess I should make
the confession before I get more criticism... :-) .It was some
stupid mistake in my code that made it look as if the thread was
not running. I modified the problem code and it is working fine.

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 <dave at pythonapocrypha.com> wrote in message news:<mailman.1040050760.3351.python-list at python.org>...
> On 16 Dec 2002, Anand B Pillai wrote:
> 
> > 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



More information about the Python-list mailing list