Process size in XP from Python

I have a python script that can approach the 2 GB process limit under Windows XP. On a machine with 2 GB physical memory, that can pretty much lock up the machine, even if the Python script is running at below normal priority.

Is there a way in Python to find out my own process size?

Thanks, Gerry


Asked by: Marcus968 | Posted: 01-10-2021






Answer 1

try:

import win32process
print win32process.GetProcessMemoryInfo(win32process.GetCurrentProcess())

Answered by: Lucas694 | Posted: 02-11-2021



Answer 2

By using psutil https://github.com/giampaolo/psutil :

>>> import psutil, os
>>> p = psutil.Process(os.getpid())
>>> p.memory_info()
meminfo(rss=6971392, vms=47755264)
>>> p.memory_percent()
0.16821255914801228
>>> 

Answered by: Andrew995 | Posted: 02-11-2021



Answer 3

Rather than worrying about limiting your process size at runtime, it might be better to figure out if all the pieces of data that you're currently storing in memory truly need to be in memory at all times.

You probably have plenty of disk space, and simply by creating some temporary files (see the tempfile module) there should be ample opportunity to write any data you are no longer using for the current calculation to disk. You can then read it back in later when/if you need it again. This is (simplistically) how many databases work.

While disk is considered "slow" in a computational sense, it is still very fast and it is an extremely useful tool when working with large data sets. And since you are already setting the process priority to "Below Normal" it doesn't sound like speed should be a serious issue for you anyway, whereas the memory clearly is.

Answered by: Dainton337 | Posted: 02-11-2021



Similar questions

windows - python and process

What is the best way in python find the process name and owner? Now i use WMI, but this version is too slow.


windows - Get process ID with python

How to get the current process id with python on windows? there are this function os.geteuid() but its only works with linux/unix could someone tell what it the pythonic way to get the current process id on windows.


windows - Every Python IDLE run starts a new process

Windows 7: I'm using Python3.2 with IDLE. Every time I edit and load my program, I get a new "pythonw.exe *32" process (as shown by Windows Task Manager)--even if the program just prints Hello World. This is a special nuisance if the program is on a static RAM drive, because then I have to kill each of these processes individually before I can eject my drive. Is this a bug in IDLE? Is there a way I can prev...


windows 7 - Keep ram for python process

I have a python script (exe made with py2exe) that runs on several machines. This Python exe does two things periodically; one thread writes a py file for further treatment while another thread listens on a tcp port using the pyZmq module. The has run perfectly for days, using around 12Mo of ram. Now here is the problem : these machines also run 3dsmax rendering. 3dsmax takes ...


windows - Python kill batch file process failed

I'm attempting to use Python subprocess.Popen to run a batch file, which executes xfoil.exe and feeds it some parameters. Then it waits until xfoil.exe exits. I've used the following code as a batch runner, which waits for the process to exit with a timeout. The process is killed if it times out. def Bat_Runner(args, **kwargs): """ Batch runner :par...


how to run python 'pyw' file in Windows 10 process

Good Day All, I finished writing the site blocker process and then i renamed the "py" file by appending "w", double clicked to run it yet the process did not show up in the task manager. I tried it a few times and yet nothing showed up. Mind you I am on Win 10 OS. You have any suggestions to help fix this such that is shows up in the task manager as pythonw.exe process ?


python - psutil windows process memory usage

My objective is simply to list the top 5 processes hogging memory, and exactly how much memory they are "using". I have read through the docs and it seems that process.memory_info().rss is what I want, however this number comes out significantly smaller than what the windows task manager is telling me is in the 'Private Working Set'. Even when I list out the whole contents of memory_info n...


windows - Getting name of process from PID using python

My goal is to be able to access the name of a process that I know the process name and PID of. I'm not looking for the process name. That's the general goal but to be clear I'll use the specific example I'm working on. I want to be able to determine the current song being played on Spotify, but can't use the API because I would want to determine it every couple of seconds and I'm not sure it would be a good idea to...


Get usage disk of a Windows process by name in Python

I would like to create a script that wait until a specific process has 0 MB/s of disk usage. import time import psutil def get_process(name): process = None for p in psutil.process_iter(): if name in p.as_dict()["name"].lower(): process = p return process def wait_proce...


windows - How do I use Python to kill a process that has run out of memory?

This question already has answers here:


windows - python and process

What is the best way in python find the process name and owner? Now i use WMI, but this version is too slow.


windows - Get process ID with python

How to get the current process id with python on windows? there are this function os.geteuid() but its only works with linux/unix could someone tell what it the pythonic way to get the current process id on windows.


windows - How to list all dlls loaded by a process with Python?

I want to list all the dlls loaded by a process, like this: How could I get the information with Python on Windows?


windows - Using Python, how can I obtain the running process and the exe name for that process?

Suppose that I have an exe running and its name is myexe.exe. On Windows, I can see the process for myexe.exe in Process Explorer. Using Python, how can I obtain the process ID of myexe.exe and shut it down?


windows - Every Python IDLE run starts a new process

Windows 7: I'm using Python3.2 with IDLE. Every time I edit and load my program, I get a new "pythonw.exe *32" process (as shown by Windows Task Manager)--even if the program just prints Hello World. This is a special nuisance if the program is on a static RAM drive, because then I have to kill each of these processes individually before I can eject my drive. Is this a bug in IDLE? Is there a way I can prev...


windows 7 - Keep ram for python process

I have a python script (exe made with py2exe) that runs on several machines. This Python exe does two things periodically; one thread writes a py file for further treatment while another thread listens on a tcp port using the pyZmq module. The has run perfectly for days, using around 12Mo of ram. Now here is the problem : these machines also run 3dsmax rendering. 3dsmax takes ...


winapi - Python Windows API dump process in buffer then REGEX search

I have the following Python code using the Windows APIs to do a minidump of a process, works ok dumping to a file but I need a way to keep the dump in a memory buffer then do a REGEX search against it. Couldn't come out with a way other than dumping to a file. Any idea? import win32security, win32con, win32api, win32file, ctypes import re from constants.structures import MINIDUMP_TYPES_CLASS dbghelp = ctyp...


windows - python 2 [Error 32] The process cannot access the file because it is being used by another process

I'm working with python 2 and have read several posts about this error i.e(this post). However, I'm still getting the error. What I do is: I read the files in a directory, if any of the files contains a specific string, I delete the directory. def select_poo(): path = os.walk('/pail...


windows - Python kill batch file process failed

I'm attempting to use Python subprocess.Popen to run a batch file, which executes xfoil.exe and feeds it some parameters. Then it waits until xfoil.exe exits. I've used the following code as a batch runner, which waits for the process to exit with a timeout. The process is killed if it times out. def Bat_Runner(args, **kwargs): """ Batch runner :par...


How to check in Python if Windows process is running when its service has stopped?

Some Windows processes keep running for a few minutes after their service has stopped. Is there a way in Python to detect that?


windows - Create an icon in memory with win32 in python

What's a good way to generate an icon in-memory in python? Right now I'm forced to use pygame to draw the icon, then I save it to disk as an .ico file, and then I load it from disk as an ICO resource... Something like this: if os.path.isfile(self.icon): icon_flags = win32con.LR_LOADFROMFILE | win32con.LR_DEFAULTSIZE hicon = win32gui.LoadImage(hinst, ...


How to find out if there is data to be read from stdin on Windows in Python?

This code select.select([sys.stdin], [], [], 1.0) does exactly what I want on Linux, but not in Windows. I've used kbhit() in msvcrt before to see if data is available on stdin for reading, but in this case it always returns 0. Additionally msvcrt.getch() returns '\xff' whereas sys.stdin.read(1) returns ...


How can I read system information in Python on Windows?

Following from this OS-agnostic question, specifically this response, similar to data available from the likes of /proc/meminfo on Linux, how can I read system information from Windows using Python (including, but...


In the windows python console, how to make Tab = four spaces?

Hello I would like that when I am in the python console tabbing will give me four spaces. Any ideas?


windows xp - Cygwin and Python 2.6

New to python (and programming). What exactly do I need from Cygwin? I'm running python 2.6 on winxp. Can I safely download the complete Cygwin? It just seems like a huge bundle of stuff. Well, I keep running into modules and functionality (i.e. piping output) which suggest downloading various cygwin components. Will cygwin change or modify any other os functionality or have any other side effects?


windows - Using DPAPI with Python?

Is there a way to use the DPAPI (Data Protection Application Programming Interface) on Windows XP with Python? I would prefer to use an existing module if there is one that can do it. Unfortunately I haven't been able to find a way with Google or Stack Overflow. EDIT: I've taken the example code pointed to by "dF" and tweaked it into a standalone library which can be simply used at a high ...


windows - How do I create a webpage with buttons that invoke various Python scripts on the system serving the webpage?

I'm a hobbyist (and fairly new) programmer who has written several useful (to me) scripts in python to handle various system automation tasks that involve copying, renaming, and downloading files amongst other sundry activities. I'd like to create a web page served from one of my systems that would merely present a few buttons which would allow me to initiate these scripts remotely. The problem is that I do...


How do I create a windows service with Python


Python script - SCP on windows

How is it possible to do secure copy using python (windows native install - ActivePython). Unfortunately pexpect module is for unix only and we don't want cygwin locally. I wrote a script that based on pscp.exe win tool - but always stops at first execution becuse of fingerprint host id. and haven't found option to switch this off. the remote hosts are running ssh-server on cygwin (win 2003 servers). Thanks


windows - Example of how to use msilib to create a .msi file from a python module

Can anyone give me an example of how to use python's msilib standard library module to create a msi file from a custom python module? For example, let's say I have a custom module called cool.py with the following code class Cool(object): def print_cool(self): print "cool" and I wa...






Still can't find your answer? Check out these communities...



PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python



top