Skip to content

Graph traversal with Networkx (Python)

I’m playing a bit with Networkx to manage a graph of dependencies. Let’s say I have this Graph which each letter represent a server So here we can see that before starting A we need to start H and B and to start H we need to start C and then to start B wee need to start C and

how can i safely write to a file when using Flask?

I need to write a method on a Flask server which will write part of the request to a log file. However, if I understand correctly, Flask is multi-threaded, and there’s a good chance that writing to a file is not safe. Admittedly, I am more or less new to Python and multi-threaded programming in general,…

How to check whether screen is off in Mac/Python?

How do I check whether the screen is off due to the Energy Saver settings in System Preferences under Mac/Python? Answer Quick and dirty solution: call ioreg and parse the output. In my computer, the value for CurrentPowerState is 4 when the screen is on and 1 when the screen is off. Better solution: use ctyp…

python tkinter with threading causing crash

I have written a python tkinter code using threads so as the tkinter wizard updates automatically by tkinter mainloop running in the main thread and background process running in separate thread. But I noticed, that python crashes after some time when running the code. Moreover its random in nature but python…

Filter an evaluated QuerySet in Django

The requirement is for me to be able to access members of an evaluated QuerySet by a string attribute, in this case name. I don’t like the idea of looping over a QuerySet as it seems like there is a more efficient way. After I’ve called something like: And I evaluate it with something like: What i…