473,626 Members | 3,974 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(i nt));
*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=va lgrind-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_Reallo c, 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 1429

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

Similar topics

2
5338
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 exceptions.OSError: (10, 'No child processes') in <bound method spawn.__del__ of <pexpect.spawn instance at 0x403d938c>> ignored What is happening and how do I get rid of the exception?
2
2359
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 scripts to work with various flavours of UNIX. However, OpenVMS is causing me problems. The tcl scripts work perfectly across UNIX and VMS. I'm converting them from tcl to python simply because python is more scalable and allows for better code...
5
4517
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 difficult it is do the following in python (without pexpect): - logon to a remote system using ssh - do an 'ls' and exit the remote shell - print the output from the remote shell session.
0
2153
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") child.logfile = sys.stdout
5
2729
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 dynamically through a web interface from a client machine. I use a bit of php to setup a simple form, and then have the php execute my python script on the server. The python script tries to 'su' to root to create the share, create dirs, set perms,...
1
10638
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 the error: #Begin Code import sys import pexpect
8
5863
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 * import pexpect import os
5
8627
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 I have done so far is spawned a child for ssh. 1) Now what do I do to execute shell_cmd(ls and grep), spawn another child? 2) Can I use the same child that was spawned for ssh, if so how?
2
5368
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 import os
0
8266
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8705
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8638
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8365
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8505
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7196
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.