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)
Related
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."
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.
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
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Monitoring files/directories with python
I am making an API server that allows hot-deploying of code. And yes, there are dozens of questions about re-importing modules. I just want to monitor a directory, and when a change is detected, perform an action.
path_to_monitor="c:\\app\\package"
def action():
do_something()
dm=dir_monitor(path_to_monitor,action)
dm.start()
I need a solution that is mature and cross-platform.
You can use a Python thread which uses os.listdir() to list files. If you want to monitor other file properties than the file name, os.stat might help you.
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.)