how to know if object gets deleted in python
I have an object in the heap and a reference to it. There are certain circumstances in which the object gets deleted but the reference that points to its location doesn't know that. How can i check if there is real data in the heap?
For example:
from PySide import *
a = QProgressBar()
b = QProgressBar()
self.setIndexWidget(index,a)
self.setIndexWidget(index,b)
Then the a
object gets deleted but print(a)
returns a valid address. However if you try a.value()
- runtime error occurs (C++ object already deleted).
a is None
returns False
.
python pyside
add a comment |
I have an object in the heap and a reference to it. There are certain circumstances in which the object gets deleted but the reference that points to its location doesn't know that. How can i check if there is real data in the heap?
For example:
from PySide import *
a = QProgressBar()
b = QProgressBar()
self.setIndexWidget(index,a)
self.setIndexWidget(index,b)
Then the a
object gets deleted but print(a)
returns a valid address. However if you try a.value()
- runtime error occurs (C++ object already deleted).
a is None
returns False
.
python pyside
add a comment |
I have an object in the heap and a reference to it. There are certain circumstances in which the object gets deleted but the reference that points to its location doesn't know that. How can i check if there is real data in the heap?
For example:
from PySide import *
a = QProgressBar()
b = QProgressBar()
self.setIndexWidget(index,a)
self.setIndexWidget(index,b)
Then the a
object gets deleted but print(a)
returns a valid address. However if you try a.value()
- runtime error occurs (C++ object already deleted).
a is None
returns False
.
python pyside
I have an object in the heap and a reference to it. There are certain circumstances in which the object gets deleted but the reference that points to its location doesn't know that. How can i check if there is real data in the heap?
For example:
from PySide import *
a = QProgressBar()
b = QProgressBar()
self.setIndexWidget(index,a)
self.setIndexWidget(index,b)
Then the a
object gets deleted but print(a)
returns a valid address. However if you try a.value()
- runtime error occurs (C++ object already deleted).
a is None
returns False
.
python pyside
python pyside
edited Jul 4 '12 at 11:57
unkulunkulu
8,59222345
8,59222345
asked Jul 4 '12 at 11:29
GeneralFailure
5001827
5001827
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
use sip
module, read more about sip
here
import sip
a = QProgressBar()
sip.isdeleted(a)
False
sip.delete(a)
a
<PyQt4.QtCore.QObject object at 0x017CCA98>
sip.isdeleted(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: underlying C/C++ object has been deleted
sip.isdeleted(a) returned True for me when an object was deleted, without raising any exception.
– andrean
Oct 18 '12 at 9:40
1
This wouldn't work with PySide though, would it?
– neuronet
Aug 21 '14 at 22:51
The output shown here is wrong:sip.isdeleted(a)
will never raise that runtime error.
– ekhumoro
Nov 24 '18 at 15:13
@ekhumoro It's a six year old answer, perhaps things have changed now. :)
– Ashwini Chaudhary
Nov 24 '18 at 15:48
@AshwiniChaudhary Well, it was meant as hint to improve your answer ;-) (Ifisdelete
ever did raise an exception, that would obviously have been a bug which has long since been fixed).
– ekhumoro
Nov 24 '18 at 16:47
add a comment |
For the PySide
objects you'll need the shiboken
module to perform object queries.
Visit the shiboken module documention:
import shiboken
print shiboken.isValid(a)
3
thx for your answer! but where can I find shiboken module? the pyside wiki is dead. I built pyside from source, and only found shiboken-python2.7.dll, but no shiboken pyd.
– jichi
Mar 27 '13 at 5:16
from Shiboken import shiboken should work. See: stackoverflow.com/questions/25458572/…
– neuronet
Sep 21 '14 at 0:43
add a comment |
It is explicitly mentioned in the documentation when an object takes the responsibility for the deletion of another object. In your example, you can see this in the Qt doc :
If index widget A is replaced with index widget B, index widget A will be deleted.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f11328219%2fhow-to-know-if-object-gets-deleted-in-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
use sip
module, read more about sip
here
import sip
a = QProgressBar()
sip.isdeleted(a)
False
sip.delete(a)
a
<PyQt4.QtCore.QObject object at 0x017CCA98>
sip.isdeleted(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: underlying C/C++ object has been deleted
sip.isdeleted(a) returned True for me when an object was deleted, without raising any exception.
– andrean
Oct 18 '12 at 9:40
1
This wouldn't work with PySide though, would it?
– neuronet
Aug 21 '14 at 22:51
The output shown here is wrong:sip.isdeleted(a)
will never raise that runtime error.
– ekhumoro
Nov 24 '18 at 15:13
@ekhumoro It's a six year old answer, perhaps things have changed now. :)
– Ashwini Chaudhary
Nov 24 '18 at 15:48
@AshwiniChaudhary Well, it was meant as hint to improve your answer ;-) (Ifisdelete
ever did raise an exception, that would obviously have been a bug which has long since been fixed).
– ekhumoro
Nov 24 '18 at 16:47
add a comment |
use sip
module, read more about sip
here
import sip
a = QProgressBar()
sip.isdeleted(a)
False
sip.delete(a)
a
<PyQt4.QtCore.QObject object at 0x017CCA98>
sip.isdeleted(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: underlying C/C++ object has been deleted
sip.isdeleted(a) returned True for me when an object was deleted, without raising any exception.
– andrean
Oct 18 '12 at 9:40
1
This wouldn't work with PySide though, would it?
– neuronet
Aug 21 '14 at 22:51
The output shown here is wrong:sip.isdeleted(a)
will never raise that runtime error.
– ekhumoro
Nov 24 '18 at 15:13
@ekhumoro It's a six year old answer, perhaps things have changed now. :)
– Ashwini Chaudhary
Nov 24 '18 at 15:48
@AshwiniChaudhary Well, it was meant as hint to improve your answer ;-) (Ifisdelete
ever did raise an exception, that would obviously have been a bug which has long since been fixed).
– ekhumoro
Nov 24 '18 at 16:47
add a comment |
use sip
module, read more about sip
here
import sip
a = QProgressBar()
sip.isdeleted(a)
False
sip.delete(a)
a
<PyQt4.QtCore.QObject object at 0x017CCA98>
sip.isdeleted(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: underlying C/C++ object has been deleted
use sip
module, read more about sip
here
import sip
a = QProgressBar()
sip.isdeleted(a)
False
sip.delete(a)
a
<PyQt4.QtCore.QObject object at 0x017CCA98>
sip.isdeleted(a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: underlying C/C++ object has been deleted
edited Jul 4 '12 at 11:54
answered Jul 4 '12 at 11:32
Ashwini Chaudhary
174k34314382
174k34314382
sip.isdeleted(a) returned True for me when an object was deleted, without raising any exception.
– andrean
Oct 18 '12 at 9:40
1
This wouldn't work with PySide though, would it?
– neuronet
Aug 21 '14 at 22:51
The output shown here is wrong:sip.isdeleted(a)
will never raise that runtime error.
– ekhumoro
Nov 24 '18 at 15:13
@ekhumoro It's a six year old answer, perhaps things have changed now. :)
– Ashwini Chaudhary
Nov 24 '18 at 15:48
@AshwiniChaudhary Well, it was meant as hint to improve your answer ;-) (Ifisdelete
ever did raise an exception, that would obviously have been a bug which has long since been fixed).
– ekhumoro
Nov 24 '18 at 16:47
add a comment |
sip.isdeleted(a) returned True for me when an object was deleted, without raising any exception.
– andrean
Oct 18 '12 at 9:40
1
This wouldn't work with PySide though, would it?
– neuronet
Aug 21 '14 at 22:51
The output shown here is wrong:sip.isdeleted(a)
will never raise that runtime error.
– ekhumoro
Nov 24 '18 at 15:13
@ekhumoro It's a six year old answer, perhaps things have changed now. :)
– Ashwini Chaudhary
Nov 24 '18 at 15:48
@AshwiniChaudhary Well, it was meant as hint to improve your answer ;-) (Ifisdelete
ever did raise an exception, that would obviously have been a bug which has long since been fixed).
– ekhumoro
Nov 24 '18 at 16:47
sip.isdeleted(a) returned True for me when an object was deleted, without raising any exception.
– andrean
Oct 18 '12 at 9:40
sip.isdeleted(a) returned True for me when an object was deleted, without raising any exception.
– andrean
Oct 18 '12 at 9:40
1
1
This wouldn't work with PySide though, would it?
– neuronet
Aug 21 '14 at 22:51
This wouldn't work with PySide though, would it?
– neuronet
Aug 21 '14 at 22:51
The output shown here is wrong:
sip.isdeleted(a)
will never raise that runtime error.– ekhumoro
Nov 24 '18 at 15:13
The output shown here is wrong:
sip.isdeleted(a)
will never raise that runtime error.– ekhumoro
Nov 24 '18 at 15:13
@ekhumoro It's a six year old answer, perhaps things have changed now. :)
– Ashwini Chaudhary
Nov 24 '18 at 15:48
@ekhumoro It's a six year old answer, perhaps things have changed now. :)
– Ashwini Chaudhary
Nov 24 '18 at 15:48
@AshwiniChaudhary Well, it was meant as hint to improve your answer ;-) (If
isdelete
ever did raise an exception, that would obviously have been a bug which has long since been fixed).– ekhumoro
Nov 24 '18 at 16:47
@AshwiniChaudhary Well, it was meant as hint to improve your answer ;-) (If
isdelete
ever did raise an exception, that would obviously have been a bug which has long since been fixed).– ekhumoro
Nov 24 '18 at 16:47
add a comment |
For the PySide
objects you'll need the shiboken
module to perform object queries.
Visit the shiboken module documention:
import shiboken
print shiboken.isValid(a)
3
thx for your answer! but where can I find shiboken module? the pyside wiki is dead. I built pyside from source, and only found shiboken-python2.7.dll, but no shiboken pyd.
– jichi
Mar 27 '13 at 5:16
from Shiboken import shiboken should work. See: stackoverflow.com/questions/25458572/…
– neuronet
Sep 21 '14 at 0:43
add a comment |
For the PySide
objects you'll need the shiboken
module to perform object queries.
Visit the shiboken module documention:
import shiboken
print shiboken.isValid(a)
3
thx for your answer! but where can I find shiboken module? the pyside wiki is dead. I built pyside from source, and only found shiboken-python2.7.dll, but no shiboken pyd.
– jichi
Mar 27 '13 at 5:16
from Shiboken import shiboken should work. See: stackoverflow.com/questions/25458572/…
– neuronet
Sep 21 '14 at 0:43
add a comment |
For the PySide
objects you'll need the shiboken
module to perform object queries.
Visit the shiboken module documention:
import shiboken
print shiboken.isValid(a)
For the PySide
objects you'll need the shiboken
module to perform object queries.
Visit the shiboken module documention:
import shiboken
print shiboken.isValid(a)
edited Jan 28 '15 at 3:15
Mark E. Haase
18.1k64961
18.1k64961
answered Jul 4 '12 at 11:54
arjenve
1,44976
1,44976
3
thx for your answer! but where can I find shiboken module? the pyside wiki is dead. I built pyside from source, and only found shiboken-python2.7.dll, but no shiboken pyd.
– jichi
Mar 27 '13 at 5:16
from Shiboken import shiboken should work. See: stackoverflow.com/questions/25458572/…
– neuronet
Sep 21 '14 at 0:43
add a comment |
3
thx for your answer! but where can I find shiboken module? the pyside wiki is dead. I built pyside from source, and only found shiboken-python2.7.dll, but no shiboken pyd.
– jichi
Mar 27 '13 at 5:16
from Shiboken import shiboken should work. See: stackoverflow.com/questions/25458572/…
– neuronet
Sep 21 '14 at 0:43
3
3
thx for your answer! but where can I find shiboken module? the pyside wiki is dead. I built pyside from source, and only found shiboken-python2.7.dll, but no shiboken pyd.
– jichi
Mar 27 '13 at 5:16
thx for your answer! but where can I find shiboken module? the pyside wiki is dead. I built pyside from source, and only found shiboken-python2.7.dll, but no shiboken pyd.
– jichi
Mar 27 '13 at 5:16
from Shiboken import shiboken should work. See: stackoverflow.com/questions/25458572/…
– neuronet
Sep 21 '14 at 0:43
from Shiboken import shiboken should work. See: stackoverflow.com/questions/25458572/…
– neuronet
Sep 21 '14 at 0:43
add a comment |
It is explicitly mentioned in the documentation when an object takes the responsibility for the deletion of another object. In your example, you can see this in the Qt doc :
If index widget A is replaced with index widget B, index widget A will be deleted.
add a comment |
It is explicitly mentioned in the documentation when an object takes the responsibility for the deletion of another object. In your example, you can see this in the Qt doc :
If index widget A is replaced with index widget B, index widget A will be deleted.
add a comment |
It is explicitly mentioned in the documentation when an object takes the responsibility for the deletion of another object. In your example, you can see this in the Qt doc :
If index widget A is replaced with index widget B, index widget A will be deleted.
It is explicitly mentioned in the documentation when an object takes the responsibility for the deletion of another object. In your example, you can see this in the Qt doc :
If index widget A is replaced with index widget B, index widget A will be deleted.
answered Jul 4 '12 at 11:44
madjar
8,8823347
8,8823347
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f11328219%2fhow-to-know-if-object-gets-deleted-in-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown