Question

Understand the Application For this lab you will create a basic application programming interface (API) for...

Understand the Application

For this lab you will create a basic application programming interface (API) for spawning multiple threads in a program using Python3's threading module.

The Program Spec

Write a program that creates a minimum of two threads with different target functions. Each thread will perform the work of each function. Each function will compute a task (described below) and print out a result.

Implementation Details

Write a program that creates a minimum of two threads using Python's threading module. The first thread will have a target function to compute and then display the result value.

The second thread will have a target function to compute and then display the result value.

In short, the nth (2 <= n <= 5) thread will have a target function to compute and then display the result.

Your program's main function will start the threads. Do be sure to coordinate the output display so that first thread displays its result before the second thread, and so on.

Test Run Requirements:  

Here are some other tips and requirements:

1. Validate that the threads get created successfully.

2. Use a minimum of 2 threads up to a maximum of 5 threads.

3. The work of the target functions can be as basic as adding 2 numbers to as complex as solving one of our earlier lab assignments...the target function operations are up to your creation.

4. Not to mix thread output (i.e. print all of job n's output prior to job n + 1's output). You will want to use synchronization methods available in the threading module.

5. Provide a screenshot of the result output of the threads.

Thread 1 job one: 5
Thread 2 job two: 8 

Deliverable:

  • yournameLab9.py  Your source code solution and a copy of the run pasted into your source submission file. Be sure to comment out your run so that your .py file will still run in the grader test bed.

Reminders:

  • Include a statement in your program header to let me know which lab you would like to replace.
  • There is no late submission window for this lab - all submissions due Tuesday, Mar. 17th 11:59 PM.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hey, following is the python code for your problem, I have added comments wherever required and a description at the end. Hope this helps !

We use os.getpid() function to get ID of current process.
print("ID of process running main program: {}".format(os.getpid()))
As it is clear from the output, the process ID remains same for all threads.

We use threading.main_thread() function to get the main thread object. In normal conditions, the main thread is the thread from which the Python interpreter was started. name attribute of thread object is used to get the name of thread.
print("Main thread name: {}".format(threading.main_thread().name))
We use the threading.current_thread() function to get the current thread object.
print("Task 1 assigned to thread: {}".format(threading.current_thread().name))

Here is a screenshot of the code.Please give a thumbs up if it helps

Here is a screenshot of the code.Please give a thumbs up if it helps

Add a comment
Know the answer?
Add Answer to:
Understand the Application For this lab you will create a basic application programming interface (API) for...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Lab 5 Instructions For Lab 5, you will be writing a more complex modular program that...

    Lab 5 Instructions For Lab 5, you will be writing a more complex modular program that uses at least two arrays, and has at least one loop that accesses the data in the arrays. As long as your program satisfies the requirements listed below, you are free to design and write any type of program that you care to. You are encouraged to be creative, and pick something that has meaning for you, because you'll have more fun. Feel free...

  • This application is for you, the shopper in mind. Putting together an itemized shopping list that...

    This application is for you, the shopper in mind. Putting together an itemized shopping list that contains the items you need, the items you want, and the anticipated cost, this program will generate a total price. This way you can decide if your shopping budget fits the bill. Example list: Price List Binder paper: 2.29 Mop: 7.50 Scouring pads: 5 Your application program will create and write a new list to an output file in which the need and wish...

  • Lab Assignment Objectives: Translate a basic application statement into a software selection solution. Learn how to...

    Lab Assignment Objectives: Translate a basic application statement into a software selection solution. Learn how to design and implement a simple program control structure. Use logical operators and boolean variables to set up test conditions. Construct applicable test cases to test your programs for correctness. Understand the Application You will obtain a grocery bill total from the customer. Depending on the amount of the grocery bill a coupon rewards amount will be calculated. The user will be informed of the...

  • in java : Create Java Application you are to create a project using our designated IDE...

    in java : Create Java Application you are to create a project using our designated IDE (which you must download to your laptop). Create the code to fulfill the requirements below. Demonstrate as stipulated below. Create a Main Application Class called AddressBookApplication (a counsole application / command line application). It should Contain a Class called Menu that contains the following methods which print out to standard output a corresponding prompt asking for related information which will be used to update...

  • This problem demonstrates the use of import module. The Python programming language has many strengths, but...

    This problem demonstrates the use of import module. The Python programming language has many strengths, but one of its best is the availability to use many existing modules for various tasks, and you do not need to be an experienced computer programmer to start using these modules. We have given you some incomplete code; note that the very first line of that code contains an import statement as follows: import math This statement enables your program to use a math...

  • Overview This assignment will give you experience on the use of classes. Understand the Application Every...

    Overview This assignment will give you experience on the use of classes. Understand the Application Every internet user–perhaps better thought of as an Internet connection–has certain data associated with him/her/it. We will oversimplify this by symbolizing such data with only two fields: a name ("Aristotle") and a globally accessible IP address ("139.12.85.191"). We could enhance these by adding other—sometimes optional, sometimes needed—data (such as a MAC address, port, local IP address, gateway, etc), but we keep things simple and use...

  • Lab #7 CSE110 - Arizona State University Topics • Basic arrays Coding Guidelines • Give identifiers...

    Lab #7 CSE110 - Arizona State University Topics • Basic arrays Coding Guidelines • Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc). • Keep identifiers to a reasonably short length. • Use upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables, methods, objects). • Use tabs or spaces to indent code within blocks (code surrounded by braces)....

  • Overview: In this lab, you will write a program called JobScheduler; it should take a single...

    Overview: In this lab, you will write a program called JobScheduler; it should take a single input file as a command-line argument. Each line in the input file has the following format: <job #> <priority> <arrival time (sec)> <duration (sec)> e.g. a file might contain: 1 3 10 100 5 2 20 50 8 4 5 100 (all values will be positive integers) These jobs might represent computer programs (or threads) that need to be run by the operating system....

  • C++ i want Lab#3 done can u make clear code so I could understand it. Lab#2The...

    C++ i want Lab#3 done can u make clear code so I could understand it. Lab#2The objective of this lab is compare the populations of various cities that lie in between Toledo and Dayton on I-75. Write a program that produces a bar illustrating the populations. The program should read the name of the city and its population from a file. Have the program continue this process until the end of file is reached. For each city, your program should...

  • Do the following project: Following is the file to be programmed in Linux kernel. Run this...

    Do the following project: Following is the file to be programmed in Linux kernel. Run this program. Include the screenshot of the results. Multi threaded Sorting Application Write a multithreaded sorting program that works as follows: A list of integers is divided into two smaller lists of equal size. Two separate threads (which we will term sorting threads) sort each sub list using a sorting algorithm of your choice. The two sub lists are then merged by a third thread—a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT