지난 몇 년 동안 사용해온이 작은 AutoIt 스크립트가 있습니다. Skype 용으로 제작 된이 제품은 RAM hoging 응용 프로그램의 메모리 사용을 필요한만큼 최소화 (Windows 전용)하고 가능한 한 낮게 유지하면서 진정으로 필요한 것을 제공하는 데 사용됩니다. 다음은 그 모습입니다 :Autoit을 Python으로 변환
#include <Misc.au3>
_Singleton("skype-memory-reducer")
Opt("TrayMenuMode", 1)
Opt("TrayOnEventMode", 1)
TrayCreateItem("Quit")
TrayItemSetOnEvent(-1, "Bye")
TraySetState()
Global Const $interval = 2000 ; interval at which the memory is freed, anything below this will almost certainly only slow down your system.
;here you can add any other process,
;but be carefull which process you choose,
;bacause in some cases this will slow down your application or even your PC
Global $list = "skype.exe|skypePM.exe"
Global $processlist = StringSplit($list, "|")
While 1
For $i = 1 To UBound($processlist) - 1
$pid = ProcessExists($processlist[$i])
If $pid Then _ReduceMemory($pid)
Next
_ReduceMemory(); also reduce the memory used by the script itself...
Sleep($interval)
WEnd
Func Bye()
Exit
EndFunc ;==>Bye
;I don't remember who was the author of this UDF... (it's not me)
Func _ReduceMemory($i_PID = -1)
If $i_PID <> -1 Then
Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
Else
Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
EndIf
Return $ai_Return[0]
EndFunc ;==>_ReduceMemory
이제는 파이썬에서 똑같은 일을 해보려고합니다. 파이썬에서 완전히 원시적 인 것 또는 다른 프로세스를 호출 할 필요없이 파이썬 내에서 Autoit 스크립트를 실행할 수있는 것.
감사합니다. 감사합니다.
편집 : 그냥 넣으면 내 응용 프로그램이 결국 휴대용이되고 싶습니다. 그래서 Windows에서 DLL을 등록하지 않아도되도록 노력하고 있습니다 (누군가가 Win32 모듈을 사용하려고 생각한 경우). 다시 한 번 감사드립니다!
라이브러리가 존재하지 않는 한 휴대용 코드를 작성할 수있는 것은 아닙니다. 예를 들어, Windows가 저주를하는 것처럼, 리눅스가 저주를하는 것처럼 코드를 작성할 수 있습니다. – Corbin
평상시처럼 ... 지금까지 무엇을 시도 했습니까? StackOverflow는 특정 질문을위한 것입니다. 뭔가를 시도해보고 잘 정의 된 문제가 발생하면 여기에 질문하십시오. – Amber
오케이, 사양이 있습니다. 급여에 대해 이야기 할 수 있습니다. – joaquin