472,779 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,779 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.write('caught %d, elapsed %d\n' % (signal, time.time()-t)

print 'running'

t = time.time()

sig.signal(sig.SIGXCPU, exceed)
sig.signal(sig.SIGSEGV, exceed)

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

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?

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

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)

Jul 5 '06 #1
0 1186

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

Similar topics

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 >>>...
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...
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...
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
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...
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...
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...
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...
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); ...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: lllomh | last post by:
How does React native implement an English player?
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.