Skip to content

Exception in finalizer of custom encoder #1256

@danabr

Description

@danabr

Environment

  • Pythonnet version: master
  • Python version: 3.7
  • Operating System: Windows 10

Details

I am using a custom encoder defined in Python to work around the conversion of IList to Python lists (see #963 (comment)):

# Prevent Python.NET from converting IList to Python lists
from Python.Runtime import PyObjectConversions
from Python.Runtime.Codecs import RawProxyEncoder
class  ListAsRawEncoder(RawProxyEncoder):
  __namespace__ = 'Python.Runtime.Codecs'
  def CanEncode(self, clr_type):
    return clr_type.Name == 'IList`1' and clr_type.Namespace == 'System.Collections.Generic'

list_encoder = ListAsRawEncoder()
PyObjectConversions.RegisterEncoder(list_encoder)

This works fine until I have called Python.Runtime.PythonEngine.Shutdown, and GC kicks in. Then there is this exception:

Unhandled exception
Exception thrown:
System.InvalidOperationException: Handle is not initialized.
   at System.Runtime.InteropServices.GCHandle.Free()
   at Python.Runtime.PythonDerivedType.Finalize(IPythonDerivedType obj)
   at Python.Runtime.Codecs.ListAsRawEncoder.Finalize()

The crash started happening after #958 was merged.

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy