How to determine machine architecture in Python? [duplicate] - python

This question already has answers here:
Is there a reliable way to determine the system CPU architecture using Python? [duplicate]
(2 answers)
How to identify which OS Python is running on?
(27 answers)
Closed 10 months ago.
I'm wondering how to find the architecture of the machine python is running on and save it to a string.
The only other example I've been able to find works only on Windows, and doesn't even detect the proper architecture if it's Windows on Arm. Any solutions would be greatly appreciated.
Thanks,
NullUsxr

import platform
print(platform.system())
According to https://docs.python.org/3/library/platform.html#platform.system it says the function would "Returns the system/OS name, such as 'Linux', 'Darwin', 'Java', 'Windows'. An empty string is returned if the value cannot be determined."

Related

How to have a subprogramm in another programming language [duplicate]

This question already has answers here:
How do I run a Python script from C#?
(8 answers)
Run a python script from unity, to use its output (text file) in my game later
(4 answers)
Closed 1 year ago.
I want to make a Unity game that gives data to a subprogram written in Python and this subprogram gives back an answer, that is then processed in the C# game.
I don't really know how to approach this.
Can I run python code from C# somehow or do I let two separate programs running, that exchange data somehow?
Both programs also need access to the same database.
You can make a python server using flask or fastAPI and then access it from C#. I am not sure how to get that done with C#(I dont know C# :( ), but there must be some libraries to call servers. Also, you could save the database on the cloud such as mongoDB.

Python - Core Speed [duplicate]

This question already has answers here:
Getting processor information in Python
(10 answers)
Closed 7 years ago.
I'm trying to find out where this value is stored in both windows and osx, in order to do some calculations to make a better task distribution.
Core speed in Hz
Thanks in advance.
Using the platform.process() command only returns the name not the speed
I only managed to get it trough this:
import subprocess
info=subprocess.check_output(["wmic","cpu","get", "name"])
print info.split('#')[1].split(' ')[1]
But for the moment i have no way to tell if it will always return the same result in every machine (no access to other computers right now)
Machine ID
There is currently no cross platform python way of getting a Machine ID, however this has been asked before:
Get a unique computer ID in Python on windows and linux
if you just want the machine name use platform.node()
Number of cores
The multiprocessing module contains the multiprocessing.cpu_count() method
Cores speed in Hz
There is currently no cross platform python way of getting cpu frequency, however this has been asked before: Getting processor information in Python

Fastest way to check in python if a file exists and get its path in a very wide tree of subdirectories [duplicate]

This question already has answers here:
Find a file in python
(9 answers)
Closed 8 years ago.
So my problem is I have a directory with over 1000 subdirectories and I want the most efficient way to check if a certain file is in them. Is there a way to do this without stepping through each directory until I find it? I would prefer a pythonic way of doing this but anything that can be run through os.system would be acceptable as long as it is efficient. Thank you!
As mentioned in http://bugs.python.org/issue11406 walk is slower than it should be, community came up with an alternative of course.
Assuming that by fastest you mean run time, you should use scandir:
https://github.com/benhoyt/scandir/#readme

Python limit usage to Linux only [duplicate]

This question already has answers here:
How can I find the current OS in Python? [duplicate]
(5 answers)
Closed 9 years ago.
I have a program I'm thinking through right now and doing tons of investigating on. One of the stipulations with the program is that I want it so it can only run on Linux. I DO NOT want the program to be usable on Windows or Apple...Linux only. I have my reasons.
I know you can use certain modules(tkinter...root.mainloop()), ie, that will cause a program to not run in Windows if you leave certain things out. Is there a way you can accomplish the same task without using any particular module...just 'base code'?
Just test for Linux:
import platform
import sys
if platform.system() != 'Linux':
sys.stderr('Linux required\n')
sys.exit(1)

Only allow 1 instance of a python script [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Python: single instance of program
What is the best way to insure that only 1 copy of a python script is running? I am having trouble with python zombies. I tired creating a write lock using open("lock","w"), but python doesn't notify me if the file already has a write lock, it just seems to wait.
Try:
import os
os.open("lock", os.O_CREAT|os.O_EXCL)
The documentation for os.open and its flags.
Your question is similar to this one: What is the best way to open a file for exclusive access in Python?. The answers given there should help you with your issue.
(Use the flag combination portalocker.LOCK_EX!|portalocker.LOCK_NB to return quickly. If the file is locked by another process, your script should get an exception.)

Categories

Resources