简体   繁体   中英

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 all available ram on the system, leaving only 4Mo of ram for my script. In this state, the reporting (py file writing) thread runs correctly, but the one that listens on the tcp port doesn't work anymore (sending msg to the machine don't get received).

However, this python exe process runs on high level priority :

set_nice(psutil.HIGH_PRIORITY_CLASS)

So, how can I reserve 14Mo of ram for my process, so that no other process running can take this ram ? Or another way to avoid the exe to 'give' his ram to other processes?

Thanks, Kib

You can use the Win32 call VirtualLock . I don't see any easy python examples, and don't have a windows machine handy to play around, but it might be relatively easy.

Outside of Python ProcessHacker seems like it might be able to do it, but I can't verify.

In general though, this is a bad idea. I think you may have a more serious issue going on. Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM