Re: threads problem in python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gabriel Genellina

    Re: threads problem in python

    En Tue, 13 May 2008 06:42:13 -0300, Astan Chee <stanc@al.com.a uescribió:
    I have 2 classes in python, the first one runs first and and then the
    first one calls the second class. I want it to run the second class as a
    separate thread but I want the first one to wait until the second class
    is dead.
    Im having problem in both killing the second class when its done and
    making the first class wait for it to finish.
    Im very confused on doing threads in python.
    I'm confused trying to understand your requirements too. "run a class?"
    Threads execute code, it's easier to think of them as *functions* that are
    executed at the same time (or almost).
    So you have a function A that runs first, and creates a second thread that
    will execute function B. Then A will wait for B to finish. What do you
    want to do in A while it's waiting? Nothing? Then why to use a second
    thread? Or is it a graphical interfase? GUI libraries like wxPython, Qt
    and others have specific ways to execute backgroung tasks while keeping
    the user interface responsive - you should tell us which one you're using
    in that case.

    --
    Gabriel Genellina

  • castironpi@gmail.com

    #2
    Re: threads problem in python

    On May 13, 5:38 am, "Gabriel Genellina" <gagsl-...@yahoo.com.a r>
    wrote:
    En Tue, 13 May 2008 06:42:13 -0300, Astan Chee <st...@al.com.a uescribió:
    >
    I have 2 classes in python, the first one runs first and and then the  
    first one calls the second class. I want it to run the second class as a 
    separate thread but I want the first one to wait until the second class  
    is dead.
    Im having problem in both killing the second class when its done and  
    making the first class wait for it to finish.
    Im very confused on doing threads in python.
    >
    I'm confused trying to understand your requirements too. "run a class?"
    Threads execute code, it's easier to think of them as *functions* that are 
    executed at the same time (or almost).
    So you have a function A that runs first, and creates a second thread that 
    will execute function B. Then A will wait for B to finish. What do you  
    want to do in A while it's waiting? Nothing? Then why to use a second  
    thread? Or is it a graphical interfase? GUI libraries like wxPython, Qt  
    and others have specific ways to execute backgroung tasks while keeping  
    the user interface responsive - you should tell us which one you're using  
    in that case.
    >
    --
    Gabriel Genellina
    I don't mean to be impertinent, but are you making any cents with the
    assignment? Both free-ers and workers come in here. I am a free-er
    who has reason to doubt that money-driven programs get stuck at that
    kind of ambiguity. I hold that money keeps you out of that mess.

    However, there are a number of things we can do to help, but as I, per
    se, am only one person, I may not give you the best advice to start
    with. How do you find the 'threading.py' docs?

    Comment

    • Gabriel Genellina

      #3
      Re: threads problem in python

      En Tue, 13 May 2008 20:46:51 -0300, Astan Chee <stanc@al.com.a uescribió:
      Sorry, I mean functions not classes. Well, actually, one is a class and
      another is a function. So when the script (its a free game btw) runs, it
      instantiates the first class and somewhere in the middle of processing
      the first class, I need to call a function as a separate thread, I also
      want to wait for the function to complete and I was wondering how python
      handles the thread of this function? Does it die when the function
      completes? Anyway, I know it sounds silly to have 2 threads when I can
      do it with one, but Im using wx to render opengl objects using pygame.
      So it has to be a separate thread, otherwise wx wont play nice. Is there
      a simple example of how I can do this?
      That's why I asked about the GUI library used. For wx see


      --
      Gabriel Genellina

      Comment

      Working...