Python Forum
How To Unload Windows Native Extension ( .pyd )?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How To Unload Windows Native Extension ( .pyd )?
#1
I am looking for a way to get the Python interpreter to release a native Python extension file ( .pyd ) so that I can delete the file when running on Windows.

I have a native Python extension, written in Rust, that is named "core" and is compiled to a windows DLL with a .pyd extension creating the file core.pyd. I put this core.pyd file in the root of my Python module which is named arsenal-blender.

In my arsenal-blender python module I import the native library like so:

from . import core
To be clear, this is all working. I am able to execute the code from core module and it works fine.

My problem is that, after importing the core module, I need a way to tell Python to "unload" the module so that Windows will allow me to delete the core.pyd file.

The reason I need to be able to do this is because arsenal-blender is a Blender plugin and Blender will try to delete the arsenal-blender folder and everything in it when the plugin is uninstalled. The issue is that Blender, and its Python instance, is still running and the core.pyd file is still open in the Python interpreter, so Windows will not allow me to delete the file.

Is there any way for me to get the Python interpreter to release that file so that it can be deleted?

This is only a problem on Windows because Unix is able to simply "unlink" the file while Python is still using it.
Reply


Messages In This Thread
How To Unload Windows Native Extension ( .pyd )? - by zicklag - Jan-01-2020, 02:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  View and extend native python class PythonDev 2 1,679 Oct-24-2020, 08:59 PM
Last Post: Gribouillis
  Error in compiling cython extension on Python 3.6.4 on Windows 8 goldenmean 3 5,819 Jun-05-2019, 09:37 PM
Last Post: Larz60+
  Native support for array-slicing syntax? nxs 1 2,279 Apr-22-2019, 02:34 AM
Last Post: ichabod801
  Pythonista script with iPhone's native Clock app Sharkman157 0 2,627 Sep-27-2018, 05:23 PM
Last Post: Sharkman157
  How to play a song .wav or .mp3 with audioop native library IvanSilva 3 6,596 Mar-14-2018, 10:49 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020