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

Cleaning up after C module

Hello,

I have a Python module written in C that spawns and kills processes
using OS-specific mechanisms. I want to kill all spawned processes when
the interpreter exits. I tried to wrap every spawned process in a
Python object like this:

import cmodule
class Process:
__init__(self, execname): self.pid = cmodule.spawn(execname)
__del__(self): cmodule.kill(self.pid)

p = Process("foo")

but this does not work, I am getting and exception inidicating that
'cmodule' is 'None' in '__del__()'.

Moreover, the Language Reference states that "It is not guaranteed that
__del__() methods are called for objects that still exist when the
interpreter exits", so it looks like this approach is wrong anyway. How
do I do this right?

Thanks very much in advance
Grzegorz

PS: Python 2.3.3

Jul 18 '05 #1
1 1277
<j1*****@hotmail.com> wrote:
I have a Python module written in C that spawns and kills processes
using OS-specific mechanisms. I want to kill all spawned processes when
the interpreter exits. I tried to wrap every spawned process in a
Python object like this:

import cmodule
class Process:
__init__(self, execname): self.pid = cmodule.spawn(execname)
__del__(self): cmodule.kill(self.pid)

p = Process("foo")

but this does not work, I am getting and exception inidicating that
'cmodule' is 'None' in '__del__()'.
module-level names may be cleaned away before your objects, so if you want
to make sure you can reach a module-level object, create your own binding:

def__del__(self, cmodule=cmodule): cmodule.kill(self.pid)
Moreover, the Language Reference states that "It is not guaranteed that
__del__() methods are called for objects that still exist when the
interpreter exits", so it looks like this approach is wrong anyway. How
do I do this right?


the "atexit" module might be what you need.

</F>

Jul 18 '05 #2

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

Similar topics

1
by: StinkFinger | last post by:
Hello all, After enabling sessions for my website I have approx. 785 files in my sessiondata folder. Now, I know what these are, however, I don't know when/how is the best way to clean them...
1
by: Mikey | last post by:
Do NativeWindows get destroyed when the app shuts down? While my app is running I can Spy++ and see my NativeWindow handle. After app shutdown it's no longer there. But this is confusing...
1
by: puzzlecracker | last post by:
It is sort of open-ended question, thus pardon the clarity herein. Let's say I have library (dll, .so, doesn't matter really), and I pass it a pointer, to Foo (Foo *). How should that library...
0
by: Now You Know | last post by:
Carpet Cleaners Los Angeles Home Carpet Rug Upholstery Cleaning Phone 1 310 925 1720 OR 1-818-386-1022 Local Call California Wide We offer carpet cleaning services such as; Steam Cleaning, Dry...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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
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...
0
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...
0
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...

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.