473,804 Members | 2,195 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unbound names in __del__

Hallöchen!

When my __del__ methods are called because the program is being
terminated, I experience difficulties in calling functions that I
need for a clean shutdown of my instances. So far, there has been
only one of these functions, and a class-local alias solved the
problem. However, now there are many of them.

Is there a way to detect whether the program is being terminated?
(In this case, I wouldn't care and return from __del__ immediately.)

Or do you know a cleaner solution? For example, if I have

import vpp43

would it help to say

def __init__(self):
__vpp43 = vpp43
...

to guarantee that I can access all the routines in vpp43 in the
__del__ method?

Tschö,
Torsten.

--
Torsten Bronger, aquisgrana, europa vetus
Jul 19 '05
13 1412
Peter Hansen <pe***@engcorp. com> writes on Fri, 17 Jun 2005 08:43:26 -0400:
...
And I don't recall the last time I saw a __del__ in third-party code I
was examining.
What's your use case for del?


I had to use one a few days ago:

To call the "unlink" method of a "minidom" object when
its "container" is destroyed.

It would have been possible to let the cyclic garbage
collector find and eliminate the cyclic "minidom" objects.
But, DOMs may be large and I create lots of them in
a short time (each in its own container)...
Dieter

Jul 19 '05 #11
Torsten Bronger wrote:
Torsten Bronger wrote:
keithley = GpibInstrument( 14)
keithley.write( "*IDN?")
print keithley.read()

[on using atexit] However, this doesn't close sessions while the program is running.
If the programmer has the above code in a function which is called
repeatedly, he may run into trouble. IIRC my current VISA DLL has
only 256 session slots.


Hmm... it sounds to me as though the design of this DLL is such that one
is expected to hold a session open for the duration of the application.
So instead of creating new GpibInstrument objects as needed, then just
sort of dropping them, the programmers would have to create the required
instrument objects at the start of the program and reuse them when needed.

But that's as far as my thoughts take me on this, without working
directly with you. I guess you'll have to explore the __del__ approach
through to its conclusion before you'll be confident it won't work (or
perhaps you'll find a solution after all!).

-Peter
Jul 19 '05 #12

"Torsten Bronger" <br*****@physik .rwth-aachen.de> wrote in message
news:87******** ****@wilson.rwt h-aachen.de...
Torsten Bronger wrote:
keithley = GpibInstrument( 14)
keithley.write( "*IDN?")
print keithley.read() A keithley.close( ) would be a wart in my opinion; instead I want
to hide the whole session thing from the programmer. Besides, I
haven't yet given up the hope that the issues with __del__ can be
tackled.
However, this doesn't close sessions while the program is running.
If the programmer has the above code in a function which is called
repeatedly, he may run into trouble. IIRC my current VISA DLL has
only 256 session slots.


Deleting during a run is a different issue from deleting during program
shutdown, which is where you started us. In CPython, 'del keithley' will,
if keithley is the last reference to the object, dependably delete and
object, calling __del__ on the way. For other implementations , deleting
the last reference makes the object eligible to be deleted 'sometime' (if
and when garbage collection happens). So an explicit close is the only
dependable cross-implementation method that I know of.

Terry J. Reedy

Jul 19 '05 #13
Hallöchen!

"Terry Reedy" <tj*****@udel.e du> writes:
"Torsten Bronger" <br*****@physik .rwth-aachen.de> wrote:

[...]
However, this doesn't close sessions while the program is
running. If the programmer has the above code in a function
which is called repeatedly, he may run into trouble. IIRC my
current VISA DLL has only 256 session slots.
Deleting during a run is a different issue from deleting during
program shutdown, which is where you started us.


Well, I talked about shutdown in the OP because only *then* I had
experienced problems. Cleaning up is important in every phase of
the program, though.
[...] So an explicit close is the only dependable
cross-implementation method that I know of.


I agree, but I could live with the little danger of a Python
implementation that frees so slowly that the DLL runs out of
handles. One could add a close() method for emergency use.
However, this __del__ thingy is so damn tempting ... ;-)

Tschö,
Torsten.

--
Torsten Bronger, aquisgrana, europa vetus
Jul 19 '05 #14

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

Similar topics

0
2477
by: seth | last post by:
Last week I encountered an AttributeError in my unit tests that I wasn'table to catch with an "except AttributeError" statement. The problem stemmed from a class that raised an error inside __init__and defined a __del__ method to clean up resources. I then discovered asimilar problem in the shelve module. This led me to two importantdiscoveries: 1. Attributes defined in __init__ after an error is raised will not be apart of the...
2
1646
by: Kepes Krisztian | last post by:
Hi ! I very wonder, when I get exp. in java with GC. I'm Delphi programmer, so I get used to destructorin objects. In Java the final method is not same, but is like to destructor (I has been think...). And then I try with some examples, I see, that the Java GC is
6
2594
by: Peter Abel | last post by:
I have an application, which is an instance of a class with a deeply nested object hierarchy. Among others one method will be executed as a thread, which can be stopped. Everything works fine except that when deleting the main instance - after the thread has been stopped - the __del__ method will not be carried out. Tough a simple example works as expected: >>> class A: .... def __init__(self):
13
2039
by: Emmanuel | last post by:
Hi, I run across this problem, and couldn't find any solution (python 2.2.2) : Code : =========== from __future__ import generators >>> class titi:
1
2029
by: schwerdy | last post by:
Hello developers! I'm using Python 2.3.4 under debian Sarge and want to write a small logger class. My source code reads: #*************************************************** import sys, time from fcntl import * class Log(object): """
2
2086
by: Mike C. Fletcher | last post by:
I'm looking at rewriting parts of Twisted and TwistedSNMP to eliminate __del__ methods (and the memory leaks they create). Looking at the docs for 2.3's weakref.ref, there's no mention of whether the callbacks are held with a strong reference. My experiments suggest they are not... i.e. I'm trying to use this pattern: class Closer( object ): """Close the OIDStore (without a __del__)""" def __init__( self, btree ): """Initialise the...
1
1494
by: Erwan Adam | last post by:
Hello all, Can someone reproduce this bug ... I use : python Python 2.4.3 (#2, Sep 18 2006, 21:07:35) on linux2 Type "help", "copyright", "credits" or "license" for more information. First test :
6
2878
by: George Sakkis | last post by:
I'm baffled with a situation that involves: 1) an instance of some class that defines __del__, 2) a thread which is created, started and referenced by that instance, and 3) a weakref proxy to the instance that is passed to the thread instead of 'self', to prevent a cyclic reference. This probably sounds like gibberish so here's a simplified example: ==========================================
6
2694
by: Volker Neurath | last post by:
Hi all, I have a Problem with combobox-property "NotInList" and an unbound Form. The situation: On my main form i have three comboboxes for data-exchange (here: Names of distributor, reseller and final customers, the whole database is made for storing information about quotatations - no, not for quoting itself) ut the boxes actually may not contain all our distributors and reseller's
0
9715
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
10352
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
10354
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
10097
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...
1
7642
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
6867
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3835
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.