File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -881,3 +881,31 @@ def release_memory() -> None:
881
881
logger .warning ("Failed to release CPU memory." )
882
882
except Exception :
883
883
logger .warning ("Failed to release CPU memory." )
884
+
885
+ elif platform .system () == "Windows" :
886
+ try :
887
+ from ctypes import wintypes as wt
888
+
889
+ kernel32 = ctypes .WinDLL ("kernel32" , use_last_error = True )
890
+ psapi = ctypes .WinDLL ("psapi" , use_last_error = True )
891
+
892
+ GetCurrentProcess = kernel32 .GetCurrentProcess
893
+ GetCurrentProcess .restype = wt .HANDLE
894
+ hProcess = GetCurrentProcess ()
895
+
896
+ EmptyWorkingSet = psapi .EmptyWorkingSet
897
+ EmptyWorkingSet .argtypes = [wt .HANDLE ]
898
+ EmptyWorkingSet .restype = wt .BOOL
899
+ EmptyWorkingSet (hProcess )
900
+
901
+ SetProcessWorkingSetSize = kernel32 .SetProcessWorkingSetSize
902
+ SetProcessWorkingSetSize .argtypes = [
903
+ wt .HANDLE ,
904
+ ctypes .c_size_t ,
905
+ ctypes .c_size_t ,
906
+ ]
907
+ SetProcessWorkingSetSize .restype = wt .BOOL
908
+ SIZE_T_MAX = ctypes .c_size_t (- 1 ).value # 0xFFFFFFFFFFFFFFFF on x64
909
+ SetProcessWorkingSetSize (hProcess , SIZE_T_MAX , SIZE_T_MAX )
910
+ except Exception :
911
+ logger .warning ("Failed to release CPU memory." )
You can’t perform that action at this time.
0 commit comments