473,387 Members | 1,897 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,387 software developers and data experts.

Problem with running external process

There is a script running continuously which executes an external
script in a loop using os.spawnlp(os.P_WAIT, 'extscript.py') function.
After several hundred executions (cycles of the loop), the main script
gets an exception while trying to start the process. This situation is
repeated until the main script is killed. Before it is killed, no other
command can be executed - I'm getting the message:

-bash: fork: Resource temporarily unavailable.

How to properly execute another process from my script?

Jan 20 '06 #1
8 2056
see the help for ulimit (builtils) :

-$ help limit

Jan 21 '06 #2
Quoth "ToMasz" <t_*******@o2.pl>:
| There is a script running continuously which executes an external
| script in a loop using os.spawnlp(os.P_WAIT, 'extscript.py') function.
| After several hundred executions (cycles of the loop), the main script
| gets an exception while trying to start the process. This situation is
| repeated until the main script is killed. Before it is killed, no other
| command can be executed - I'm getting the message:
|
| -bash: fork: Resource temporarily unavailable.
|
| How to properly execute another process from my script?

Not sure what's causing this. I suggest you invoke "ps" after a
hundred iterations or so - maybe "ps -ef", or "ps wwaux" on BSD
platforms like MacOS. I think the output may show a large number
of processes, and you will know where they came from.

Donn Cave, do**@drizzle.com
Jan 21 '06 #3
This is the result of ulimit command on my machine:

core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 1014
virtual memory (kbytes, -v) unlimited

It looks like either pipe size or stack size may be too low. But my
main script must be running all the time to collect data so how much
should I increase these values to allow infinite executions of external
process?

Jan 23 '06 #4
On 23 Jan 2006 04:33:17 -0800,
"ToMasz" <t_*******@o2.pl> wrote:
... how much should I increase these values to allow infinite
executions of external process?


That sounds like a bad idea. Long before you've run an infinite number
of processes, a real resource will be exhausted.

You are probably creating zombie processes (you can check with /bin/ps).
To get rid of them, execute os.waitpid(-1, os.WNOHANG) (or something
similar to that) periodically from within your python script. Possibly
execute that statement repeatedly until it indicates that there are no
more zombies. A good time/place to do this is right before you start
another process.

Regards,
Dan

--
Dan Sommers
<http://www.tombstonezero.net/dan/>
Jan 23 '06 #5
Yes, each time the process is created, it remains.

os.waitpid(-1, os.WNOHANG) doesn't work before starting the process
for the first time.

I tried this:

pid = os.fork()
if pid == 0:
os.execl('ext_script.py','ext_script.py')
else:
(pid,status) = os.waitpid(pid, 0)

It seems to work without leaving zombies.

Jan 23 '06 #6
On 23 Jan 2006 10:03:28 -0800,
"ToMasz" <t_*******@o2.pl> wrote:
Yes, each time the process is created, it remains. os.waitpid(-1,
os.WNOHANG) doesn't work before starting the process for the first
time.
Argh. That's what I get for looking at my example too quickly. ;-)

Of course: the best place for os.waitpid is immediately *after*
starting a new process. :-/
I tried this: pid = os.fork()
if pid == 0:
os.execl('ext_script.py','ext_script.py')
else:
(pid,status) = os.waitpid(pid, 0) It seems to work without leaving zombies.


If your parent process just sits around and waits for each child process
to finish before moving on, why not use

os.spawnl(os.P_WAIT, 'ext_script.py')

instead of forking and execing "manually"?

Regards,
Dan

--
Dan Sommers
<http://www.tombstonezero.net/dan/>
Jan 24 '06 #7
No, no, that wasn't my intention (I'm just not conscious enough what's
going on with these fork, exec, spawn.. functions).
My parent process should start the child process and go back to it's
tasks. Before executing it for the next time the parent should check if
the previous child process is done and start it again.

Is it what these lines do?

os.spawnlp(os.P_NOWAIT,'ext_script.py','')
os.waitpid(-1, os.WNOHANG)

Jan 24 '06 #8
In article <11**********************@o13g2000cwo.googlegroups .com>,
"ToMasz" <t_*******@o2.pl> wrote:
No, no, that wasn't my intention (I'm just not conscious enough what's
going on with these fork, exec, spawn.. functions).
My parent process should start the child process and go back to it's
tasks. Before executing it for the next time the parent should check if
the previous child process is done and start it again.

Is it what these lines do?

os.spawnlp(os.P_NOWAIT,'ext_script.py','')
os.waitpid(-1, os.WNOHANG)


No, do you see them doing it? "Check if the previous child
process is done?"

In your original post you said you were using os.P_WAIT,
but I suppose you really were using os.P_NOWAIT all along,
right?

This case may call for a working sample program that makes a
genuine attempt to do what you want to do.

Donn Cave, do**@u.washington.edu
Jan 24 '06 #9

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

Similar topics

3
by: Wolfie | last post by:
I'm having a strange problem running a jar file I created using Eclipse. The application works correctly inside the IDE -- it compiles, runs, etc. So I exported it to a jar file and am trying to...
3
by: Myron Turner | last post by:
I'm not sure whether this question belongs entirely here or in a perl group--but probably it requires knowledge of both. I've written a perl module, currently in use, which does asynchronous...
7
by: Ron Fidel | last post by:
Hi, I'm not able to run external applications from ASP .NET (C#) with the Process class. The program appears in the Windows Task Manager but doesn't run.
3
by: Oenone | last post by:
In VB6, it's possible to create a project with a class library within it. The project can then be run with F5, and it sits and waits for an external process to create an instance of one of its...
8
by: Kevin D. | last post by:
Please note, I already posted this on the MySQL official forum, but received no response. I thought I'd try again in another location. My apologies to anyone reading this twice... Despite...
11
by: Tyron | last post by:
Is there a possibility to run an external process (exe) in on of my C# Apps Thread? I would need that because I don't want them to run anymore when my programm crashes. Also I don't want to have...
4
by: Dylan Parry | last post by:
Hi folks, I'm writing a program that needs to execute an external program and wait for it to finish running before it can make use of the output from that program. Specifically, the external...
12
by: kimiraikkonen | last post by:
Hi there, There is a problem about progress bar; although the "progressbar1.visible = True" is present for my invisible "progressbar1" control to make visible when button1 is clicked, before...
1
by: webotronics | last post by:
Hi, I need to add a timeout for external programs, as the external program sometimes never dies (it's a ClearQuest multisite call to the shipping server, that sometimes never ends, but simply...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
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,...
0
jinu1996
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 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.