GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — RuntimeError: wrapped C/C++ object of type _Event has been deleted · Issue #265 · wxWidgets/Phoenix

RuntimeError: wrapped C/C++ object of type _Event has been deleted #265

New issue
Copy link
New issue
Copy link
Closed
Closed
RuntimeError: wrapped C/C++ object of type _Event has been deleted#265
Copy link

Description

@wettenhj
wettenhj
opened on Apr 6, 2017
Issue body actions
"""
Minimal code to reproduce wx.PyEvent issue.

Output on my laptop:

sys.executable: /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
sys.version: 2.7.10 (v2.7.10:15c95b7d81dc, May 23 2015, 09:33:12) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]
wx.version(): 3.0.3.dev2891+36b8076 osx-cocoa (phoenix)
ThreadWorker 1: event._getAttrDict().keys() = ['nextEvent']
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in __bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 763, in run
    self.__target(*self.__args, **self.__kwargs)
  File "pyeventissue.py", line 45, in ThreadWorker
    % event._getAttrDict().keys())
RuntimeError: wrapped C/C++ object of type _Event has been deleted

"""
import sys
import threading

import wx
import wx.lib.newevent as NE

MyEventClass, myEventBinder = NE.NewEvent()


def MyEventHandler(event):
    """
    Event handler which starts a thread worker (taking event as an argument).

    Uncommenting the event.Clone() stuff fixes the above RuntimeError for me.
    """
    # if 'phoenix' in wx.PlatformInfo:
    #     event = event.Clone()
    def ThreadWorker(event):
        sys.stdout.write("ThreadWorker 1: event._getAttrDict().keys() = %s\n"
                         % event._getAttrDict().keys())
        wx.CallAfter(wx.BeginBusyCursor)
        sys.stdout.write("ThreadWorker 2: event._getAttrDict().keys() = %s\n"
                         % event._getAttrDict().keys())
    threading.Thread(target=ThreadWorker, args=[event]).start()


class MyApp(wx.App):
    def OnInit(self):
        self.frame = wx.Frame(None, title="MyApp")
        self.frame.Bind(myEventBinder, MyEventHandler)
        self.frame.Show()

        wx.CallAfter(self.AfterMainLoopHasStarted)
        return True

    def AfterMainLoopHasStarted(self):
        nextEvent = wx.PyEvent()
        wx.PostEvent(self.frame, MyEventClass(nextEvent=nextEvent))

sys.stdout.write("\nsys.executable: %s\n" % sys.executable)
sys.stdout.write("sys.version: %s\n" % sys.version)
sys.stdout.write("wx.version(): %s\n" % wx.version())

MyApp().MainLoop()

Activity

  1. RobinD42 commented on Apr 6, 2017

    @RobinD42
    RobinD42
    on Apr 6, 2017
    Member
    More actions

    Ok, I wasn't thinking things all the way through yesterday. It is working as expected and the event should be cloned before giving it to the worker thread.

    Basically, Clone is called when wx.PostEvent is called, and the clone is put on the pending event queue. Later, after the event has been processed and its event handler returns, it is removed from the queue and that destroys the C++ object for the cloned event. In your example it appears that it is happening when the thread blocks momentarily for setting the busy cursor.

  2. RobinD42
    closed this as completedon Apr 6, 2017
  3. chaitanya-m
    added a commit that references this issue on Aug 9, 2018

    In handlers.py 491-495, we don't want to bail because of these flags …

    6177a5b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.