How can I check how many cores my computer has?
Is it possible to do this in a Python-app? 9 7255
On Tue, 29 Jul 2008 15:53:47 -0700, defn noob wrote:
How can I check how many cores my computer has? Is it possible to do
this in a Python-app?
Well you can try the functions in the 'platform' module, although in my
box(debian) nothing useful comes out. I don't think there's a simple &
portable way, you probably have to find one specific to your platform .
(if you are on linux, you can parse the output of 'cat /proc/cpuinfo')
On Jul 29, 5:53*pm, defn noob <circularf...@yahoo.sewrote:
How can I check how many cores my computer has?
Is it possible to do this in a Python-app?
If you're using Windows, get PyWin32:
win32api.GetSystemInfo
tuple = GetSystemInfo()
Retrieves information about the current system.
Win32 API References
Search for GetSystemInfo at msdn, google or google groups.
Return Value
The return value is a tuple of 9 values,
which corresponds to the Win32 SYSTEM_INFO structure.
The element names are:
dwOemId
dwPageSize
lpMinimumApplicationAddress
lpMaximumApplicationAddress
dwActiveProcessorMask
dwNumberOfProcessors
dwProcessorType
dwAllocationGranularity
(wProcessorLevel,wProcessorRevision)
>>import win32api win32api.GetSystemInfo()
(0, 4096, 65536, 2147418111, 3L, 2, 586, 65536, (6, 3846))
|
processors
On Jul 29, 7:44*pm, Mensanator <mensana...@aol.comwrote:
On Jul 29, 5:53*pm, defn noob <circularf...@yahoo.sewrote:
How can I check how many cores my computer has?
Is it possible to do this in a Python-app?
If you're using Windows, get PyWin32:
win32api.GetSystemInfo
tuple = GetSystemInfo()
Retrieves information about the current system.
Win32 API References
Search for GetSystemInfo at msdn, google or google groups.
Return Value
The return value is a tuple of 9 values,
which corresponds to the Win32 SYSTEM_INFO structure.
The element names are:
dwOemId
dwPageSize
lpMinimumApplicationAddress
lpMaximumApplicationAddress
dwActiveProcessorMask
dwNumberOfProcessors
dwProcessorType
dwAllocationGranularity
(wProcessorLevel,wProcessorRevision)
>import win32api win32api.GetSystemInfo()
(0, 4096, 65536, 2147418111, 3L, 2, 586, 65536, (6, 3846))
* * * * * * * * * * * * * * * * *|
* * * * * * * * * * * * * * * * *processors
This: http://pyprocessing.berlios.de/ has a method that returns CPU
count.
defn noob wrote:
How can I check how many cores my computer has?
Is it possible to do this in a Python-app?
Why do you care? Python can't use more than one of them at
a time anyway.
John Nagle
On Wed, Jul 30, 2008 at 2:22 PM, John Nagle <na***@animats.comwrote:
defn noob wrote:
>> How can I check how many cores my computer has? Is it possible to do this in a Python-app?
Why do you care? Python can't use more than one of them at
a time anyway.
Per Python process, but you might fork multiple processes and want to
know how many cores there are to know how many to fork, and which
cores to pin them to. (I don't know if there's a direct way in Python
to force it to a certain core, so I instead just wrote an extension to
interface with sched_setaffinity on Linux.)
On Linux, an almost assuredly non-ideal way to find out the number of
cores is to read /proc/cpuinfo and look for the highest-numbered
"processor: " line (and add 1).
defn noob schrieb:
How can I check how many cores my computer has?
Is it possible to do this in a Python-app?
processing ( http://pyprocessing.berlios.de/)
has an utility function processing.cpuCount().
Leo
Single line using /proc/cpuinfo:
numprocs = [ int(line.strip()[-1]) for line in open('/proc/cpuinfo', 'r') if \
line.startswith('processor') ][-1] + 1
On Wed, Jul 30, 2008 at 2:16 PM, Dan Upton <up***@virginia.eduwrote:
>
On Wed, Jul 30, 2008 at 2:22 PM, John Nagle <na***@animats.comwrote:
defn noob wrote:
>
How can I check how many cores my computer has?
Is it possible to do this in a Python-app?
Why do you care? Python can't use more than one of them at
a time anyway.
Per Python process, but you might fork multiple processes and want to
know how many cores there are to know how many to fork, and which
cores to pin them to. (I don't know if there's a direct way in Python
to force it to a certain core, so I instead just wrote an extension to
interface with sched_setaffinity on Linux.)
On Linux, an almost assuredly non-ideal way to find out the number of
cores is to read /proc/cpuinfo and look for the highest-numbered
"processor: " line (and add 1).
-- http://mail.python.org/mailman/listinfo/python-list
On Wed, 30 Jul 2008 11:22:12 -0700, John Nagle wrote:
defn noob wrote:
>How can I check how many cores my computer has? Is it possible to do this in a Python-app?
Why do you care? Python can't use more than one of them at
a time anyway.
Why do you care why he cares? And he didn't ask how to *use* multiple
cores, but how to detect if they're there.
Maybe all he wants is to write a toy program that outputs "Hello Fred,
your computer has N cores in the CPU. Have a nice day!".
I don't expect that Python will have a built-in core-counting function.
You would probably need to ask the operating system. On Linux, you could
do this:
import os
text = os.popen('cat /proc/cpuinfo').read()
How you would do it in Windows or Mac, I have no idea.
--
Steven
Steven D'Aprano <st***@REMOVE-THIS-cybersource.com.auwrote:
I don't expect that Python will have a built-in core-counting function.
You would probably need to ask the operating system. On Linux, you could
do this:
import os
text = os.popen('cat /proc/cpuinfo').read()
How you would do it in Windows or Mac, I have no idea.
One way on windows:
>>import win32pdhutil def howmanycores():
for i in range(9999):
try: win32pdhutil.GetPerformanceAttributes("Processor(% d)" % i,"%
Processor Time")
except: break
return i
>>print howmanycores()
2
--
Duncan Booth http://kupuguy.blogspot.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: mrbog |
last post by:
Tell me if my assertion is wrong here:
The only way to prevent session hijacking is to NEVER store
authentication information (such as...
|
by: Jared |
last post by:
Radio Button or Check Box and Event Procedures
I need to insert either radio buttons or check boxes onto my form. I'm
not sure which to use, or...
|
by: Stephen |
last post by:
Hi,
I am trying to copy files from one computer to another, the problem I am
facing is that the program chokes when the other computer is not...
|
by: Coaster |
last post by:
I am designing a process which will spawn a good number of threads and some
of them will execute a c++ process which is quite memory intensive...
|
by: Jekyll |
last post by:
hi,
I have two questions,
1/ is there any OS function which return me the number of core on each
processor on my computer (callable from C++)
2/...
|
by: Akash |
last post by:
Hi,
I am using getProcessTimes API for calculating CPU Usage
On a Multi-Core processor i have observed that the %CPU Usage that is
multiple of the...
|
by: whisk3rs |
last post by:
Hello, I have a conceptual question. I need to write a program that
will take as input a list of images and then process each image
individually...
|
by: Jon Harrop |
last post by:
I'd like to measure performance results as a function of the number of cores
by restricting parallel FX to using only a subset of my cores. Is this...
|
by: Carl Johansson |
last post by:
If a multithreaded .NET application is executed on a computer with a
multicore processor. Will the application automatically run the threads on...
|
by: jalbright99669 |
last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: Matthew3360 |
last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
|
by: AndyPSV |
last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...
| |