Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Python Multiprocessing and Date Handling

Project Overview

This academic Jupyter Notebook project demonstrates foundational Python concepts through two focused exercises:

  • Working with dates and text files
  • Creating and coordinating multiple processes with Python’s multiprocessing module

The notebook combines date formatting and parsing, file input/output, function definition, child-process creation, process startup, and completion handling.

Objectives

The project practices how to:

  • Retrieve the current system date
  • Serialize a date using ISO format
  • Write the formatted date to a text file
  • Read file contents into a Python string
  • Parse the string back into a date object
  • Define a worker function
  • Create multiple child processes
  • Start processes with start()
  • Wait for process completion with join()
  • Protect process-starting code with the __main__ guard

What the Notebook Does

1. Date and File Handling

The first section:

  1. Retrieves the current date with date.today().
  2. Converts the date to ISO format.
  3. Writes the resulting string to today.txt.
  4. Reads the file contents into today_string.
  5. Prints the stored date string.
  6. Parses the string back into a Python date object.
  7. Prints the parsed date.

The notebook opens today.txt in write mode, so running the first code cell creates the file or replaces its existing contents.

2. Multiprocessing

The second section:

  1. Defines a worker() function.
  2. Generates a random delay for each worker.
  3. Pauses each worker for its assigned delay.
  4. Prints the current timestamp after the delay.
  5. Creates three independent child processes.
  6. Starts each process.
  7. Waits for all three processes to finish.

Concurrency Model

The notebook uses Python multiprocessing rather than threading or asynchronous programming.

Three multiprocessing.Process instances execute the same worker function. Each worker selects a random delay of less than one second, waits independently, prints the current time, and exits.

Because the delays are random, the order and timing of the worker output can vary between executions. The parent process calls join() for each child process so that it waits until all workers have completed.

Technologies

  • Python 3
  • Jupyter Notebook
  • Python standard library
  • multiprocessing
  • datetime
  • Text-file input/output

No third-party runtime library is used by the notebook code.

Input and Output

Input

The notebook does not request user input. It uses:

  • The current system date
  • The current system time
  • Randomly generated wait durations

File Output

Running the first code cell creates or overwrites:

today.txt

The file is created in the notebook’s current working directory and contains the current date in ISO format:

YYYY-MM-DD

Console Output

The date-handling cells print the stored date string and the parsed date.

Each child process is intended to print a timestamp after completing its random delay. Exact timestamps and output order vary by execution.

The committed notebook contains the two date outputs but does not store output from the multiprocessing cell.

Getting Started

Prerequisites

You will need:

  • Python 3
  • Jupyter Notebook

Setup

Clone the repository:

git clone https://github.com/asmaayasser1/Programming-Assignment--Concurrency-in-Python.git
cd Programming-Assignment--Concurrency-in-Python

Install Jupyter Notebook if it is not already available:

python -m pip install notebook

Launch the notebook:

jupyter notebook "Programming Assignment -Concurrency .ipynb"

Run the cells from top to bottom. The date-handling cells create and use today.txt in the current working directory.

Platform Note

Multiprocessing startup and child-process output can behave differently across operating systems and Jupyter environments. The notebook includes the standard if __name__ == '__main__': guard around process creation, but some notebook environments may display child-process output outside the notebook interface.

Skills Demonstrated

  • Python date handling
  • ISO date formatting
  • Date-string parsing
  • Text-file writing and reading
  • Context-manager usage
  • Function definition
  • Random delay generation
  • multiprocessing.Process
  • Process startup with start()
  • Completion handling with join()
  • The __main__ guard
  • Basic parent and child process lifecycle management
  • Jupyter Notebook workflow

Limitations

  • The notebook does not measure execution time or provide a performance benchmark.
  • It does not compare multiprocessing with sequential execution or threading.
  • It does not demonstrate inter-process communication.
  • It does not use shared state or shared memory.
  • It does not use locks, queues, pipes, events, pools, or semaphores.
  • The committed notebook does not store the multiprocessing timestamp output.
  • Date and timestamp results naturally change when the notebook is rerun.
  • Multiprocessing behavior and output visibility may vary by operating system and notebook environment.

Project Status

Academic Python concurrency project being refined for professional portfolio presentation.

About

Academic Python project demonstrating multiprocessing process lifecycles, date handling, and text-file I/O in a Jupyter Notebook.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages