473,322 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Re: threads problem in python

En Tue, 13 May 2008 06:42:13 -0300, Astan Chee <st***@al.com.auescribió:
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

Jun 27 '08 #1
2 1153
On May 13, 5:38*am, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
En Tue, 13 May 2008 06:42:13 -0300, Astan Chee <st...@al.com.auescribió:
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?
Jun 27 '08 #2
En Tue, 13 May 2008 20:46:51 -0300, Astan Chee <st***@al.com.auescribió:
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
http://wiki.wxpython.org/LongRunningTasks

--
Gabriel Genellina

Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Bart Nessux | last post by:
Could someone explain the concept of threads and how I might use them in Python? I was a math major, not a CS major (theory instead of practice). Most of my programming knowledge has grown out of...
3
by: Ronan Viernes | last post by:
Hi, I have created a python script (see below) to count the maximum number of threads per process (by starting new threads continuously until it breaks). ###### #testThread.py import...
8
by: Alban Hertroys | last post by:
Hello, I'm using psycopg to insert records in a number of threads. After the threads finish, another thread runs to collect the inserted data. Now, my problem is that psycopg let's my threads...
11
by: Przemys³aw Ró¿ycki | last post by:
Hello, I have written some code, which creates many threads for each connection ('main connection'). The purpose of this code is to balance the load between several connections ('pipes'). The...
4
by: Steve Horsley | last post by:
I am trying to start two threads to do some time consuming work. This is my first stab at threading, and it isn't working as I expect. Instead of the threads starting when I call start(), they seem...
4
by: Rhamphoryncus | last post by:
First a bit about myself. I've been programming in python several years now, and I've got several more years before that with C. I've got a lot of interest in the more theoretical stuff (language...
1
by: Leonard J. Reder | last post by:
Hello Mark, I took your three day course here at JPL and recall that you said something was wrong with the implementation of threads within Python but I cannot recall what. So what is wrong...
29
by: Jeffrey Maitland | last post by:
Hello all, I am in the process of writing a multithreading program and what I was wondering is a sleep command in an executing function will affect the threads below it? Here is a basic example...
41
by: Carl J. Van Arsdall | last post by:
Hey everyone, I have a question about python threads. Before anyone goes further, this is not a debate about threads vs. processes, just a question. With that, are python threads reliable? Or...
6
by: nikhilketkar | last post by:
What are the implications of the Global Interpreter Lock in Python ? Does this mean that Python threads cannot exploit a dual core processor and the only advantage of using threads is in that...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.