In Python, What Are Some Disadvantages to Using os.execlp to Fork a Process?

Question
In Python you are familiar with importing the os module and using different exec variations. What are some reasons that you would not use os.execlp?

Answer
1. If you use os.execlp to call another program, that program is more likely to return “Killed”. The resources of the child process are, by default, more limited in part because the fork operation is expensive from a system’s resources perspective.

How Do You Get Python to Compute How Long Something Took?

Problem scenario
You want to check the runtime duration of a section of Python code. How do you compute the amount of time something took in Python?

Solution
Write a program like this:

import datetime, time
t1 = datetime.datetime.now()
time.sleep(5) # replace this line with the section of code you want to time
t2 = datetime.datetime.now()
t3 = t2 – t1
print(“Time format is in hours:minutes:seconds:seconds_decimals”)
print(t3) …

In Python, How Do You Call a Bound Function as a New Thread with the thread Module?

Problem scenario
You want to write a program to call a bound function in a new thread. How do you do this?

Solution
Run this program (e.g., python foobar.py):

import _thread as thread
class mighty:
def cool():
print(“Cool.”)
def contint():
print(“Hello!”)
if name == “main”:
foobar = thread.start_new_thread(mighty.cool, () )
print(“thread finished…exiting”)

In Python, How Do You Call a Function as a New Thread with the threading Module?

Problem scenario
(The old problem scenario was “You want to write a program to call a unbound function in a new thread with the threading module. How do you do this?”)

You want to write a program to call a function in a new thread with the threading module. How do you do this?

Solution
Run this program (e.g.,

How Do You Troubleshoot “Errno::ENOMEM: Cannot allocate memory -” or Some Other “out of memory” Error in Linux?

Problem scenario
You go to /var/log/ for the program or application that is not working properly. You look for the word “error.” You see HeapDumpOnOutofMemoryError or “OnOutOfMemoryError=kill -9” messages.

Or you get this error on the terminal that says “Errno::ENOMEM: Cannot allocate memory.” How might you troubleshoot out of memory errors on Linux?

Solution

Possible solution #1
Add more memory,

What Are the Recommended Practices of Logging?

Problem scenario
The primary purposes of logging include troubleshooting (root cause analysis of poor performance, debugging unintended behavior, or resolving catastrophic failures). In some cases logging is used for monitoring of resource utilization and planning of changes. What patterns or characteristics of a good logging system (consistent with what some may phrase as “best practices”)?

Solution
Here are 13 traits of good logging.

How Do You Write a Python Program to Create New Processes with the multiprocessing Library?

Problem scenario
You want to create new processes with the multiprocessing library in Python. What should you do?

Solution
Run this program:

“”” In a duplicate terminal window, run this command before, during and after you run the pyhon script: sudo ps -ef | grep python | wc -l

The integer that returns will go up by two showing a new processes have been created when the program is still running. …

What Are the Recommended Practices of Monitoring?

Question
AWS’s Five Pillars of Well-Architected Framework recommend monitoring as a component of three of the pillars (operational excellence, reliability and performance efficiency).

There is no question that monitoring is important inside or outside of a public cloud. What patterns or traits might a good centralized monitoring system have (consistent with some phrase as “best practices”)?

Answer
Here are 15 characteristics of good monitoring.

What is Operational Readiness in I.T.?

Question
How would a DevOps engineer define operational readiness or what is operational readiness in I.T.?

Answer
“All things are ready, if our mind be so.” –William Shakespeare

While some people would say it is more of a state*, others may say it is more of a journey**. Operational readiness is having sufficient staff and automation to maintain the minimum level of service that the business requires for a given product or service.

In Python Are Dictionaries Much Slower in Performance Compared to Lists or Tuples?

Problem scenario
You want to know how dictionaries perform as iterables in Python. In Python for printing the values of every key-value pair in a dictionary, is it faster or slower than printing every item in a list? How does it compare to a tuple?

Solution
For this example we use integer keys in the dictionary. Keys can be strings or other objects.