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

Confusion with resource.setrlimit() and subprocesses

I am trying to run a subprocess within given time and memory restrictions.
The resource module kind of works for me, but I do not understand why and am seeking an
explanation. Also, the signal module is not behaving as I'd expect it to.

Demo code with questions:

==========
import subprocess as sub
import resource as r
import signal as sig
import time, sys

def exceed(signal, stackFrame):
"log what we have caught, then exit"
f=open('/tmp/sig')
f.write('caught %d, elapsed %d\n' % (signal, time.time()-t)
f.close()
sys.exit(0)

print 'running'

t = time.time()

r.setrlimit(r.RLIMIT_CPU,(1,1))
r.setrlimit(r.RLIMIT_AS,(100000,100000))
sig.signal(sig.SIGXCPU, exceed)
sig.signal(sig.SIGSEGV, exceed)

try:
retcode=sub.call('./hog')
print 'done with', retcode ### QUESTION 1
except MemoryError:
print 'exceeds mem' ### QUESTION 2

# a time consuming loop
for i in xrange(1000000000):
x = 5.23/123.33 ### QUESTION 3
===========

QUESTION 1:
When ./hog exceeds time limit, retcode==-9, meaning ./hog got a SIGKILL. This is fine with
me, but why doesn't the python script itself get the SIGKILL? Is it because it is idly
waiting for the child process to finish, thus using hardly any CPU? If both processes are
indeed so loosely coupled, I wouldn't expect the child to inherit the limits - which part
of the docs did I miss?

QUESTION 2:
Why does the subprocess module throw this exception? I thought my sig.signal(sig.SIGSEGV,
exceed) would kick in.

QUESTION 3:
Similarly, if I do the time-expensive stuff inside the python script, why do I receive
SIGKILL immediately, instead of one second after SIGXCPU (which the script should catch)

TIA,
Mitja
Jul 5 '06 #1
0 1212

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

Similar topics

4
by: Jane Austine | last post by:
Running Python 2.3 on Win XP It seems like socket is working interdependently with subprocesses of the process which created socket. ------------------------------------ #the server side >>>...
2
by: Marcos | last post by:
Hi guys, I realise this question has been answered in one form or another many times before but I can't quite find the solution I need. I am trying to run multiple subprocesses from a python...
2
by: Dave Kirby | last post by:
I am working on a network management program written in python that has multiple threads (typically 20+) spawning subprocesses which are used to communicate with other systems on the network. This...
9
by: Patrick Fisher | last post by:
Hi All If I Take DateFrom from DateTo in a 31 day month I get 30 days because 31-1=30, is there a way of getting the correct answer without having to us a lookup table? Patrick
4
by: FDude | last post by:
Hello folks: I am just starting to delve into the DUMPS from the ILDASM utility. Can I do anything useful with the outputted IL code? Can someone give me some references to working with .IL...
3
by: Dara Durum | last post by:
Hi ! Py2.4, Win32. I need to optimize a program that have a speciality: hash (MD5/SHA1) the file contents (many files). Now I do this in a simple python program, because (what a pity) the...
1
by: Gal Diskin | last post by:
Hi all, I'm writing a python program using threads to open several subprocesses concurrently (using module subprocess) and wait on them. I was wondering if there is a possibilty that a thread will...
4
by: GiJeet | last post by:
Every example I see regarding opening a file uses paths like this: FileStream inputStream = new FileStream ("C:\\file.txt", FileMode.Open, FileAccess.Read); Great if the file is always on the...
2
by: mvjohn100 | last post by:
Hello, Following code is executed in program as super user . but it doesn't effective . what may be the reason? struct rlimit rl; rl.rlim_cur = 5000; setrlimit (RLIMIT_NOFILE, &rl); ...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.