Skip to content

Run function in another thread

So say there are two running codes: script1 and script2. I want script2 to be able to run a function in script1. script1 will be some kind of background process that will run “forever”. The point is to be able to make an API for a background process, E.G. a server. The unclean way to do it would b…

Dill doesn’t seem to respect metaclass

I have recently begun working with dill. I have a metaclass, which I use to create a Singleton pattern. Always have one object at any instant. I am using dill to serialise.The problem is once the object is loaded back, it doesn’t respect the Singleton pattern (enforced by metaclass) and __init__ gets ca…

Plot confidence interval of a duration series

I measured the duration of 6000 requests. I got now an Array of 6000 elements. Each element represents the duration of a connection request in milliseconds. [3,2,2,3,4,2,2,4,2,3,3,4,2,4,4,3,3,3,4,3,2,3,5,5,2,4,4,2,2,2,3,5,3,2,2,3,3,3,5,4……..] I want to plot the confidence interval in Python and in…

How do I find the index of an unknown value in python?

So basically I have a list like this – and I don’t know what val is. So how do I get the index of val (3) only knowing that it is not None Answer This one line solution gives you the first value that is not None. This returns the actual value, to get the index, look into this answer

Create a Nested list from a pandas data frame

I am trying to create a kind of nested list from a pandas data frame. I have this data frame: So I want to create a kind of nested list using the above data frame using ‘id1’ column, and ‘Name1’ and ‘Name2’ columns. For example, if we think about the first row, id1 should b…

Using If statement with string values in Python

I have a df where column A is either blank or has a string in it. I tried to write the if statement (all columns are strings) below. Basically, if there is something (any value) in df[A], then the new column value will be a concatenation of columns A, B and C. If there is no value in df[A], then