Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using resource in windows

Tags:

python

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

like image 594
jwacalex Avatar asked Jun 19 '12 14:06

jwacalex


People also ask

What is resource in Windows programming?

A resource is a text file that allows the compiler to manage objects such as pictures, sounds, mouse cursors, dialog boxes, etc. Microsoft Visual Studio makes creating a resource file particularly easy by providing the necessary tools in the same environment used to program.

How do I add a resource to Windows form?

On the Tools menu, click Resource Files. In the Resource Files dialog box, click Add. In the Add File dialog box, select the file that you updated, and then click OK.

Why are resource files used?

Resource files are files in XML format. They contain all the resources needed by an application. These files can be used to store string, bitmaps, icons, fonts.


1 Answers

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.

like image 121
Pyrce Avatar answered Sep 19 '22 13:09

Pyrce