jwacalex
jwacalex

Reputation: 517

Using resource in windows

i've got a script that uses the resource-module from python (see http://docs.python.org/library/resource.html for information). Now i want to port this script to windows. is there any alternative version of this (the python-docs are labeling it as "unix only"). if there isn't, is there any other workaround?

I'm using the following method/constant:

resource.getrusage(resource.RUSAGE_CHILDREN)
resource.RLIMIT_CPU

Thank you

PS: I'm using python 2.7 / 3.2

Upvotes: 15

Views: 15899

Answers (1)

Pyrce
Pyrce

Reputation: 8571

There's no good way of doing this generically for all "Resources"" -- hence why it's a Unix only command. For CPU speed only you can either use registry keys to set the process id limit:

http://technet.microsoft.com/en-us/library/ff384148%28WS.10%29.aspx As done here: http://code.activestate.com/recipes/286159/

IMPORTANT: Backup your registry before trying anything with registry

Or you could set the thread priority:

http://msdn.microsoft.com/en-us/library/ms685100%28VS.85%29.aspx As done here: http://nullege.com/codes/search/win32process.SetThreadPriority

For other resources you'll have to scrap together similar DLL access APIs to achieve the desired effect. You should first ask yourself if you need this behavior. Oftentimes you can limit CPU time by sleeping the thread in operation at convenient times to allow the OS to swap processes and memory controls can be done problematically to check data structure sizes.

Upvotes: 3

Related Questions