Hallo!
I have a problem with this little script written in Python:
import sys, os, time
texts = ['this is text1', 'this is text 2']
for current_text in env_sources[0:]:
pid = os.fork()
if pid == 0:
time.sleep(2)
print current_text
break
As you is create some child processes depending on the number of vars
in ?texts?. My problem is: How can I run some code after all child
processes have been finished? (The code should be run only in the
parent process.)
I tried:
import sys, os, time
texts = ['this is text1', 'this is text 2']
for current_text in env_sources[0:]:
pid = os.fork()
if pid == 0:
time.sleep(2)
print current_text
break
os.waitpid(-1, 0)
print 'this is the end'
But this didn't work, 'this is the end' will be showed several times.
Can you help me?
Tanks.
Markus 2 1303 mf****@arcor.de (Markus Franz) writes: Hallo!
I have a problem with this little script written in Python:
import sys, os, time texts = ['this is text1', 'this is text 2'] for current_text in env_sources[0:]: pid = os.fork() if pid == 0: time.sleep(2) print current_text break
As you is create some child processes depending on the number of vars in ?texts?. My problem is: How can I run some code after all child processes have been finished? (The code should be run only in the parent process.)
I tried:
import sys, os, time texts = ['this is text1', 'this is text 2'] for current_text in env_sources[0:]: pid = os.fork() if pid == 0: time.sleep(2) print current_text break os.waitpid(-1, 0) print 'this is the end'
But this didn't work, 'this is the end' will be showed several times.
import sys, os, time
texts = ['this is text1', 'this is text2']
for current_text in env_sources[0:]:
pid = os.fork()
if pid == 0:
time.sleep(2)
print current_text
break
if pid != 0:
os.waitpid(-1, 0)
print 'this is the end'
Basically, make sure that none of the children run the waitpid and
last print.
<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
"Markus Franz" <mf****@arcor.de> wrote in message
news:57**************************@posting.google.c om...
I am a little puzzled about your variable declaration and use: import sys, os, time texts = ['this is text1', 'this is text 2']
You don't seem to use 'texts',
for current_text in env_sources[0:]:
or define 'env_sources',
pid = os.fork() if pid == 0: time.sleep(2) print current_text break
so I don't see how this could run (even with indents inserted back). What
am I missing?
Terry J. Reedy This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Rech |
last post by:
Hi,
I need a little help here managing child processes in Python. I'm not so
skilled in system programming so I hope you can give me some good
suggestions.
I have a very CPU and memory...
|
by: Markus Franz |
last post by:
Hallo!
I have a problem with this little script written in Python:
import sys, os, time
texts =
for current_text in env_sources:
pid = os.fork()
|
by: Thomas |
last post by:
Hi all,
I want to execute a new program in a c++ program without
beeing blocked. After the child process is created both
processes should run idependend.
My method at the moment:
execute(...
|
by: Jason Godden |
last post by:
Hi All,
I've written a few C functions in the version 1 format as well as some SPI
based backend bits and I'm curious as to how PG treats these items when used
within plpgsql.
The set of...
|
by: msxkim |
last post by:
How to execute functions in the parent class first and then functions
in the child class? For example, I have a parent class with functions
'ONE' and 'TWO' and child class has a function 'THREE'. ...
| |
by: Fred Heida |
last post by:
Hi,
Question on Vista Run As Administrator. If i have exe which creates a child
process, using the Process class, and
this exe is Run As Asministror, is there a way to have the child process...
|
by: revenant81 |
last post by:
I'm writing a program which has to execute a command, get its output
and show it on a treeview.
This command runs for a very long time.
I want to end the execution of the command when the user...
|
by: Jason Zheng |
last post by:
This may be a silly question but is possible for os.wait() to lose track
of child processes? I'm running Python 2.4.4 on Linux kernel 2.6.20
(i686), gcc4.1.1, and glibc-2.5.
Here's what happened...
|
by: rocco.rossi |
last post by:
I'm using the Python processing module. I've just run into a problem
though. Actually, it's a more general problem that isn't specific to
this module, but to the handling of Unix (Linux processes)...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |