and in the separate thread that works on interval i am
accessing/changing some of the main frame controls. when i close my
app i get the following error:
--- error ---
raise PyDeadObjectError(self.attrStr % self._name)
PyDeadObjectError: The C++ part of the NewGui object has been deleted,
attribute access no longer allowed.
···
-----------
firstly i did stop the thread after application MainLoop(), then tried
in app OnExit method, same error.
any hints how can i safely stop the thread?
raise PyDeadObjectError(self.attrStr % self._name)
PyDeadObjectError: The C++ part of the NewGui object has been deleted,
attribute access no longer allowed.
This error means that something is trying to access something that has already been deleted.
Does your thread try to make a call to the gui during its shutdown procedure?
You can also try trapping the error if its not doing anything important for your shutdown proceedure.
try:
except wx.PyDeadObjectError:
pass
Cody
···
On Feb 21, 2009, at 4:58 PM, dejan todorović wrote:
Does your thread try to make a call to the gui during its shutdown
procedure?
Thread runs in interval, so thread tries to access gui controls even
if i stopped it on onExit application method. Do not know how/where to
safely stop it.
You can also try trapping the error if its not doing anything important for
your shutdown proceedure.
try:
except wx.PyDeadObjectError:
pass
yeah, doing that, but hoped for some more "elegant" solution.
and in the separate thread that works on interval i am
accessing/changing some of the main frame controls. when i close my
app i get the following error:
If I understand what you said here, that's the problem in itself.
Most GUI libraries are not thread safe; wxPython is no exception. Accessing GUI elements should be done from only one thread - usually the main one.
Use pubsub to send messages back to the main thread where subscribers do the GUI work on behalf of the other thread.
and in the separate thread that works on interval i am
accessing/changing some of the main frame controls. when i close my
app i get the following error:
If I understand what you said here, that's the problem in itself.
Most GUI libraries are not thread safe; wxPython is no exception. Accessing GUI elements should be done from only one thread - usually the main one.
Use pubsub to send messages back to the main thread where subscribers do the GUI work on behalf of the other thread.
Using pubsub to call things on the main thread _does not_ make it thread safe. Pubsub does direct blocking calls on the methods passed in and will not help with maintaining the safety of the main thread at all, it is exactly the same as calling the method directly from the other thread.
In a very simplified explanation pubsub does the following.
def sendMessage(msg_type, data):
for callback in subscribers.get(msg_type, list()):
callback(data)
To safely make calls to the main gui thread you need to use events, or wrap the method you are calling by using wx.CallAfter (which uses events under the hood) to call your method back on the main thread. Events are put in a queue and processed during the main threads event loop so they can be safetly picked up and called in the context of the main thread.
Does your thread try to make a call to the gui during its shutdown
procedure?
Thread runs in interval, so thread tries to access gui controls even
if i stopped it on onExit application method. Do not know how/where to
safely stop it.
Does your 'stop()' method set a flag in the thread to tell it to exit?
May need to readjust the order of operations, I can't really tell you much more without knowing what's going on inside your threads run method.
You can also try trapping the error if its not doing anything important for
your shutdown proceedure.
try:
except wx.PyDeadObjectError:
pass
yeah, doing that, but hoped for some more "elegant" solution.
thanks for your reply.
You can also check do the following check to see if the window has been deleted or not before trying to make a call to it.
if not isinstance(frame, wx.Window):
# frame has been deleted
return
else:
wx.CallAfter(doSomethingWithFrame)
Cody
···
On Feb 21, 2009, at 6:41 PM, dejan todorović wrote:
and in the separate thread that works on interval i am
accessing/changing some of the main frame controls. when i close my
app i get the following error:
If I understand what you said here, that's the problem in itself.
Most GUI libraries are not thread safe; wxPython is no exception. Accessing GUI elements should be done from only one thread - usually the main one.
Use pubsub to send messages back to the main thread where subscribers do the GUI work on behalf of the other thread.
Using pubsub to call things on the main thread _does not_ make it thread safe. Pubsub does direct blocking calls on the methods passed in and will not help with maintaining the safety of the main thread at all, it is exactly the same as calling the method directly from the other thread.
In a very simplified explanation pubsub does the following.
def sendMessage(msg_type, data):
for callback in subscribers.get(msg_type, list()):
callback(data)
To safely make calls to the main gui thread you need to use events, or wrap the method you are calling by using wx.CallAfter (which uses events under the hood) to call your method back on the main thread. Events are put in a queue and processed during the main threads event loop so they can be safetly picked up and called in the context of the main thread.
Yes. I must have been thinking about Queue. I've been using wx.CallAfter so long in my buried pubsub routines that I've largely forgotten about it.
btw, started using editra, switched from eclipse and pydev. it works
pretty well, i have some issues with auto-completion tough or i do not
know how to use it.
May need to readjust the order of operations, I can't really tell you much
more without knowing what's going on inside your threads run method.
okay, here is my thread run method since i failed fixing it with
wx.CallAfter, it just runs in interval and show/hide self.frame
controls.
When does your frame get destroyed/closed? Try stopping the thread in the Frames wx.EVT_CLOSE handler and block until the thread has stopped.
I am also assuming that all the 'self.frame.' calls in the threads run method are not directly calling gui methods on the main thread as making direct calls is going to lead to more problems as was previously discussed.
------ end of code ------
btw, started using editra, switched from eclipse and pydev. it works
pretty well, i have some issues with auto-completion tough or i do not
know how to use it.
When its able to provide completions it will do so after a '.' or '(' is inserted in the buffer.
i.e)
import sys
sys.
Hitting Ctrl+Space will also bring up a list of possible completions based on the context of the current cursor position.
Its of course not perfect but will work most of the time.
Cody
···
On Feb 22, 2009, at 12:06 PM, dejan todorović wrote: