Chapter 2: System Programming Packages

 

  1. What is the main module that allows us to interact with the Python interpreter?

The system (sys) module.

 

  1. What is the main module that allows us to interact with the OS environment, filesystem, and permissions?

The operating system (os) module

 

  1. Which modules and methods are used to list the contents of the current working directory?

The operating system (os) module and the getcwd() method.

 

  1. Which module is used to execute a command or invoke a process via the call() function?

>>> subprocess.call("cls", shell=True)

 

  1. What is the approach that we can follow in Python to handle files and manage exceptions in an easy and secure way?

We can use the context manager approach and the with statement.

 

  1. What is the difference between processes and threads?

Processes are full programs. Threads are similar to processes: they are also code in execution. However, threads are executed within a process, and the threads of a process share resources among themselves, such as memory.

 

  1. What are the main modules in Python for creating and managing threads?

There are two options:

The thread module provides primitive operations for writing multithreaded programs.

The threading module provides a more convenient interface.

 

  1. What is the limitation that Python has when working with threads?

The execution of threads in Python is controlled by the Global Interpreter Lock (GIL) so that only one thread can be executed at any time, independently of the number of processors of the machine.

  1. Which class provides a high-level interface for executing input/output tasks in an asynchronous way?
       ThreadPoolExecutors provides a simple abstraction around spinning up multiple threads and          using these threads to perform tasks in a concurrent way.
      
  2. Which is the function in the threading module that determines which thread has performed?
        We can use the threading.current_thread() function in order to determine which thread has      performed the current task.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.204.186