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

Valgrind and pexpect

Hi,
I'm using the pexpect module to spawn some processes in a testing
environment. pexpect uses, internally, os.execv. What I need to do is
valgrind python and get memory leaks from the spawned children
(assuming that python doesn't leak :)).

Here's a simple testcase:

===================
leak.c:
===================

#include <stdlib.h>
#include <stdio.h>

int main()
{
int *i = (int *) malloc(sizeof(int));
*i = 7;
printf("*i=%d\n", *i);

return 0;
}
===================
leak.py:
===================
import pexpect
import sys

child = pexpect.spawn('./leak')
child.expect('\*i=');
print 'Done'

===================
Valgrind command:
===================

valgrind --leak-check=full --trace-children=yes --tool=memcheck
--suppressions=valgrind-python.supp python ./leak.py

==30239== Memcheck, a memory error detector.
==30239== Copyright (C) 2002-2006, and GNU GPL'd, by Julian Seward et al.
==30239== Using LibVEX rev 1658, a library for dynamic binary translation.
==30239== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP.
==30239== Using valgrind-3.2.1-Debian, a dynamic binary
instrumentation framework.
==30239== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al.
==30239== For more details, rerun with: -v
==30239==
Done
==30239==
==30239== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 1092 from 8)
==30239== malloc/free: in use at exit: 702,546 bytes in 140 blocks.
==30239== malloc/free: 2,314 allocs, 2,174 frees, 1,929,320 bytes allocated.
==30239== For counts of detected errors, rerun with: -v
==30239== searching for pointers to 140 not-freed blocks.
==30239== checked 1,069,436 bytes.
==30239==
==30239== LEAK SUMMARY:
==30239== definitely lost: 0 bytes in 0 blocks.
==30239== possibly lost: 0 bytes in 0 blocks.
==30239== still reachable: 699,710 bytes in 138 blocks.
==30239== suppressed: 2,836 bytes in 2 blocks.
==30239== Reachable blocks (those to which a pointer was found) are not shown.
==30239== To see them, rerun with: --show-reachable=yes

As you can see, the 4 bytes leaked by leak.c are not reported. The
suppression file I've used is taken from:
http://svn.python.org/projects/pytho...nd-python.supp
and I have uncommented the parts related to PyObject_Free and
PyObject_Realloc, as explained there.

So, does anyone know what the correct way to do this is?

Thanks in advance,
Salvarore.
--
Salvatore Iovene
http://www.iovene.com/
Key Fingerprint: 5647 944D D5AD 2E87 00B4 7D54 2864 359D FF20 16D8
Dec 20 '07 #1
0 1411

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

Similar topics

2
by: Michael Surette | last post by:
I have been trying to automate the changing of passwords using python and pexpect. I wrote a script as a test and it works, except that it gives me an exception when it stops running: Exception...
2
by: Adrian Casey | last post by:
I have a collection of tcl expect scripts which I am converting to python using the excellent pexpect module (http://pexpect.sourceforge.net/). So far I've had great success in getting all my...
5
by: funkyj | last post by:
I love pexpect because it means I may never have to use expect again (I don't do any heavy expect lifting -- I just need simple tty control)! As a python advocate I find it embarassing how...
0
by: dwelch91 | last post by:
I'm having a problem using pexpect with 'sudo' on Ubuntu 6.06 (Dapper). Here's the program: #!/usr/bin/env python import pexpect import sys child = pexpect.spawn("sudo apt-get update")...
5
by: half.italian | last post by:
Hi all. I try not to post until I am stuck in hole with no way out. I fought with this for several hours, and am currently in the hole. I'm doing a proof of concept for creating afp shares...
1
by: Kevin Erickson | last post by:
Hello, I am attempting to use pexpect in python to copy files from a server using scp; the copy works however exceptions are thrown and it exits unsuccessfully. Below is the a sample code and...
8
by: asgarde | last post by:
hello, I'm new in Python and i would like to use Pexpect to execute a root command (i want to mount via a Pyhton script a drive) so that's my script for the moment : from os import *...
5
by: crybaby | last post by:
I need to ssh into a remote machine and check if mytest.log file is there. I have setup ssh keys to handle login authentications. How do I determine if mytest.log is there by using Pexpect. What...
2
by: yellowblueyellow | last post by:
Hey , I need to SSH into a server .. (10.8.42.38) using pexpect the username is 'admin' and password is 'abc123' so far i have the following code import pexpect import sys import time...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...

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.