Making a multithread app that runs several instances of whatever the app did before

O

olbion

Hi

I've aquired a program written in Python, and without much knowledge of
the language I'm trying to make some changes to it. The original
program starts, runs a certain process and then finishes. I want to
adapt it so that, at a certain stage of the process, a new process is
started from scratch, running at the same time as the original one.
When the original one is finished, it should exit without causing the
newer process to stop.

I've successfully achieved this using sys.popen methods to start
separate processes, but come to realise that running seperate processes
is not a very good solution, since it uses up more memory and becomes
harder to manage. I'd like the same thing to be achieved using threads.

I've come as far as being able to start the program which runs the
first thread. My problem arrises when I want the new thread to be
started. It seems that if I do this by calling a function from within
the thread, I'm unable to stop the original thread whenever that
finishes. I imagine that what I've achieved is something like:

Start file (eg start.py) starts Thread 1
Thread 1 starts a new thread (Thread 2) and becomes the parent of that
thread
Thread 2 starts a new thread (Thread 3)... and so on

I think that what I want is something like:

Start file starts Thread 1
Thread 1 informs start file that a new thread should be started; start
file starts Thread 2
.... and so on

So, if my thinking so far is correct, how can a thread cause another
thread to be started without becoming its parent?
 
S

Steve Holden

Hi

I've aquired a program written in Python, and without much knowledge of
the language I'm trying to make some changes to it. The original
program starts, runs a certain process and then finishes. I want to
adapt it so that, at a certain stage of the process, a new process is
started from scratch, running at the same time as the original one.
When the original one is finished, it should exit without causing the
newer process to stop.

I've successfully achieved this using sys.popen methods to start
separate processes, but come to realise that running seperate processes
is not a very good solution, since it uses up more memory and becomes
harder to manage. I'd like the same thing to be achieved using threads.

I've come as far as being able to start the program which runs the
first thread. My problem arrises when I want the new thread to be
started. It seems that if I do this by calling a function from within
the thread, I'm unable to stop the original thread whenever that
finishes. I imagine that what I've achieved is something like:

Start file (eg start.py) starts Thread 1
Thread 1 starts a new thread (Thread 2) and becomes the parent of that
thread
Thread 2 starts a new thread (Thread 3)... and so on

I think that what I want is something like:

Start file starts Thread 1
Thread 1 informs start file that a new thread should be started; start
file starts Thread 2
.... and so on

So, if my thinking so far is correct, how can a thread cause another
thread to be started without becoming its parent?
Read up on "demonised" (sp?) threads in the documentation from threading.

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top