### Build and install thread from source Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/installation.mdx Clones the thread repository from GitHub and installs the package locally using pip. ```sh # Clone this repository git clone https://github.com/python-thread/thread # Install the upstream package pip install -e . ``` -------------------------------- ### Set up thread for development Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/installation.mdx Clones the thread repository, installs Poetry, and then installs project dependencies using Poetry for development purposes. ```sh # Clone this repository git clone https://github.com/python-thread/thread # Install poetry pip install poetry # Install dependencies poetry install ``` -------------------------------- ### Install thread using pip Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/installation.mdx Installs the thread library using pip, a common Python package installer. ```sh pip install thread ``` -------------------------------- ### Build and install thread from source Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/installation.mdx Clones the thread repository from GitHub and installs the package locally using pip. ```sh # Clone this repository git clone https://github.com/python-thread/thread # Install the upstream package pip install -e . ``` -------------------------------- ### Set up thread for development Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/installation.mdx Clones the thread repository, installs Poetry, and then installs project dependencies using Poetry for development purposes. ```sh # Clone this repository git clone https://github.com/python-thread/thread # Install poetry pip install poetry # Install dependencies poetry install ``` -------------------------------- ### Install thread using pip Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/installation.mdx Installs the thread library using pip, a common Python package installer. ```sh pip install thread ``` -------------------------------- ### Import thread in Python Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/installation.mdx Demonstrates how to import the thread library into a Python script after installation. ```py import thread ``` -------------------------------- ### Setup Thread CLI for Development Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/command-line-interface.mdx Steps to set up the Thread CLI for development, including cloning the repository, installing Poetry, and installing project dependencies. ```sh # Clone this repository git clone https://github.com/python-thread/thread-cli # Install poetry pip install poetry # Install dependencies poetry install ``` -------------------------------- ### Install thread using pipx Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/installation.mdx Installs the thread library using pipx, which allows running Python applications in isolated environments. ```sh pipx install thread ``` -------------------------------- ### Setup Thread CLI for Development Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/command-line-interface.mdx Clones the thread-cli repository, installs Poetry, and then installs project dependencies. ```sh # Clone this repository git clone https://github.com/python-thread/thread-cli # Install poetry pip install poetry # Install dependencies poetry install ``` -------------------------------- ### Install thread using poetry Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/installation.mdx Adds the thread library as a dependency to a project managed by Poetry, a Python dependency management tool. ```sh poetry add thread # OR poetry install thread ``` -------------------------------- ### Import thread in Python Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/installation.mdx Demonstrates how to import the thread library into a Python script after installation. ```py import thread ``` -------------------------------- ### Install thread using pipx Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/installation.mdx Installs the thread library using pipx, which allows running Python applications in isolated environments. ```sh pipx install thread ``` -------------------------------- ### Install thread using poetry Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/installation.mdx Adds the thread library as a dependency to a project managed by Poetry, a Python dependency management tool. ```sh poetry add thread # OR poetry install thread ``` -------------------------------- ### Project Header and Navigation (React) Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/index.mdx This snippet demonstrates the main header section of the project, including the project title, version, a package manager component, and a 'Get Started' button. It also includes a smooth scroll button to navigate to the features section. ```javascript
{/* Section 1 */}

Thread  - v2.0.5

Get Started
{/* Section 2 */}

Features

``` -------------------------------- ### Starting Concurrent Processing Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/concurrent-processing.mdx Demonstrates how to initialize and start the concurrent processing using the ConcurrentProcessing class. ```python import thread worker = thread.ConcurrentProcessing(function = my_func, dataset = [1, 2, 3]) worker.start() ``` -------------------------------- ### Thread Management Example (Python) Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/index.mdx This Python code snippet demonstrates basic thread management, including creating and starting threads. It highlights how to use the `threading` module for concurrent execution. ```python import threading import time def worker(num): """Thread worker function""" print(f'Worker: {num} starting') time.sleep(1) print(f'Worker: {num} finishing') threads = [] for i in range(5): t = threading.Thread(target=worker, args=(i,)) threads.append(t) t.start() for t in threads: t.join() ``` -------------------------------- ### On-Demand Thread Creation and Execution Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/learn/examples/threading.mdx Demonstrates how to create a thread on-demand using `thread.Thread`, start it, and wait for its completion using `join()`. This is useful for running tasks in the background without immediate execution. ```python import time import thread def my_background_task(): time.wait(5) print('My background task is complete.') worker = thread.Thread(target=my_background_task) worker.start() print('Started background task.') worker.join() # Halt the main thread until the background thread finishes. # Terminal output: # > Started background task. # > My background task is complete. ``` -------------------------------- ### Next.js Card Navigation Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/learn/examples.mdx Demonstrates how to use Next.js components to create navigation cards with icons. This example utilizes `Card` and `Cards` from 'nextra/components' and icons from '@radix-ui/react-icons'. ```javascript import { Pencil1Icon, BarChartIcon } from "@radix-ui/react-icons"; import { Card, Cards } from "nextra/components"; } /> } /> ``` -------------------------------- ### Running ConcurrentProcessing Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/concurrent-processing.mdx Shows how to start the execution of a ConcurrentProcessing object after it has been initialized. ```python my_processor.start() ``` -------------------------------- ### Install Thread CLI with Poetry Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/command-line-interface.mdx Installs the thread-cli package using Poetry, a dependency management and packaging tool for Python. ```sh poetry add thread-cli # OR poetry install thread-cli ``` -------------------------------- ### Next.js Card Components for Navigation Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/index.mdx This snippet demonstrates the use of Next.js's `Cards` and `Card` components, along with Radix UI icons, to create a navigation interface for different documentation sections. It's used in the 'Quick Start' guide. ```jsx import { LightningBoltIcon, ExclamationTriangleIcon, GearIcon, MixIcon, CodeIcon, } from "@radix-ui/react-icons"; import { Cards, Card } from "nextra/components"; } /> } /> } /> } /> } /> } /> ``` -------------------------------- ### On-Demand Thread Creation and Execution Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/learn/examples/processing.mdx Demonstrates how to create and start a thread on-demand using `thread.ParallelProcessing`. It includes starting the worker, joining it to wait for completion, and retrieving return values. The example shows a simple processor function that waits for 5 seconds. ```python import time import thread def my_processor(x): time.wait(5) print('My processing task is complete.') return x worker = thread.ParallelProcessing(function=my_processor, dataset=(1,)) worker.start() print('Started processing task.') worker.join() # Halt the main thread until the threads finish. worker.get_return_values() # [1] # Terminal output: # > Started processing task. # > My processing task is complete. ``` -------------------------------- ### Importing ConcurrentProcessing Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/concurrent-processing.mdx Provides examples of how to import the ConcurrentProcessing class from the 'thread' library. ```python import thread thread.ConcurrentProcessing ``` ```python from thread import ConcurrentProcessing ``` -------------------------------- ### Run the Thread CLI Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/command-line-interface.mdx Basic command to execute the Thread CLI after installation. ```sh thread ``` -------------------------------- ### Initializing a Thread (On-Demand) Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/thread-class.mdx Shows how to create and start a thread by directly initializing the Thread class with a target function. ```python def my_target(): ... # Recommended way my_thread = Thread( target = my_target ) # OR # Not the recommended way my_thread = Thread(my_target) my_thread.start() ``` -------------------------------- ### Initializing a Thread (On-Demand) Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/thread-class.mdx Shows how to create and start a thread by directly initializing the Thread class with a target function. ```python def my_target(): ... # Recommended way my_thread = Thread( target = my_target ) # OR # Not the recommended way my_thread = Thread(my_target) my_thread.start() ``` -------------------------------- ### Install Thread CLI with Poetry Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/command-line-interface.mdx Installs the Thread CLI using the Poetry dependency management and packaging tool. It can be added as a project dependency or installed directly. ```sh poetry add thread-cli # OR poetry install thread-cli ``` -------------------------------- ### Build Thread CLI from Source Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/command-line-interface.mdx Clones the thread-cli repository and installs the package locally using pip. ```sh # Clone this repository git clone https://github.com/python-thread/thread-cli # Install the upstream package pip install -e . ``` -------------------------------- ### Install Thread CLI with pipx Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/command-line-interface.mdx Installs the Thread CLI using the pipx tool, which is designed for installing and running Python applications in isolated environments. ```sh pipx install thread-cli ``` -------------------------------- ### ConcurrentProcessing with Defined Function Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/concurrent-processing.mdx Shows the recommended approach of using a defined function with type hints for ConcurrentProcessing. This improves code readability and allows IDEs to provide better type inference. The example includes starting, joining, and accessing results, highlighting the inferred type of the results. ```python from thread import ConcurrentProcessing def my_target(x: int) -> int: return x + 1 worker = ConcurrentProcessing(function = my_target, dataset = [1, 2, 3]) worker.start() worker.join() worker.results ``` -------------------------------- ### Basic Python Print Statement Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/learn/thread/index.mdx This snippet shows a fundamental Python print statement. It's a simple example of outputting text to the console. ```python print("Hey I am some example code!") ``` -------------------------------- ### Dataset Chunking Example Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/concurrent-processing.mdx Shows how a dataset is split into evenly sized chunks for concurrent processing, preserving the original order. It also touches upon the calculation for individual chunk lengths. ```python chunks = [[1, 2, 3, ...], [50, 51, 52, ...], ...] # Let N be the length of the dataset # and let M be the number of threads. # The length of each chunk will can be either \lfloor{N/M + 0.5}\rfloor + 1 or N/M. ``` -------------------------------- ### Install Thread CLI with pip Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/command-line-interface.mdx Installs the thread-cli package using pip, a common Python package installer. ```sh pip install thread-cli ``` -------------------------------- ### Type-Annotated Processor Function Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/learn/examples/processing.mdx Shows how to use Python's type annotations with the `thread` library for improved type safety, compatible with Python 3.9+. This example defines a processor function with input and output type hints and demonstrates starting a worker with it. ```python import thread def processor_function(x: int) -> int: return x + 1 worker = thread.ParallelProcessing(function=processor_function, dataset=(1,)) worker.start() returned = worker.get_return_value() # list[int] ``` -------------------------------- ### Importing ParallelProcessing (Python) Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/parallel-processing.mdx Provides examples of how to import the ParallelProcessing class from the thread library. ```python import thread thread.ParallelProcessing from thread import ParallelProcessing ``` -------------------------------- ### Build Thread CLI from Source Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/command-line-interface.mdx Instructions for cloning the Thread CLI repository and installing it locally using pip. This is useful for development or when needing the latest unreleased version. ```sh # Clone this repository git clone https://github.com/python-thread/thread-cli # Install the upstream package pip install -e . ``` -------------------------------- ### Conventional Commits Examples Source: https://github.com/python-thread/thread/blob/main/CONTRIBUTING.md Examples of commit messages following the Conventional Commits standard, prefixed with the type of change. ```sh git commit -m "docs: Added README.md" git commit -m "revert: Removed README.md" git commit -m "docs: Moved README.md" ``` -------------------------------- ### Dataset Chunking Example (Python) Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/parallel-processing.mdx Shows how a dataset is divided into smaller, manageable chunks for simultaneous processing by multiple threads. ```python chunks = [[1, 2, 3, ...], [50, 51, 52, ...], ...] ``` -------------------------------- ### Thread CLI Parallel Processing - Lambda Example Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/command-line-interface.mdx Example of using the 'thread process' command to process a list of numbers using a lambda function for squaring. ```sh thread process 'lambda x: x**2' '[ i for i in range(1000) ]' ``` ```py import thread # Start processing worker = thread.ParallelProcessing( function = lambda x: x**2, dataset = [ i for i in range(1000) ] ) worker.start() worker.join() # Write output to "./output.json" with open('./output.json', 'w') as output: output.write(worker.results) ``` -------------------------------- ### Install Thread CLI with pip Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/command-line-interface.mdx Installs the Thread CLI using the pip package manager. This is a common method for Python package installation. ```sh pip install thread-cli ``` -------------------------------- ### Install Thread Package Source: https://github.com/python-thread/thread/blob/main/README.md Installs the latest version of the Thread package using pip. This is the first step to using the library in your Python projects. ```sh pip install -U thread ``` -------------------------------- ### Get Thread CLI Help Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/command-line-interface.mdx Displays the help message for the Thread CLI, showing available commands and options. ```sh thread -h/--help ``` -------------------------------- ### Install Thread CLI with pipx Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/command-line-interface.mdx Installs the thread-cli package using pipx, which allows running Python applications in isolated environments. ```sh pipx install thread-cli ``` -------------------------------- ### Get Thread CLI Help Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/command-line-interface.mdx Command to display the help message for the Thread CLI, showing available commands and options. ```sh thread -h/--help ``` -------------------------------- ### Killing Threads Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/concurrent-processing.mdx Provides examples of how to schedule threads for termination, with options for yielding and setting a timeout. ```python import thread worker = thread.ConcurrentProcessing(function = my_func, dataset = [1, 2, 3]) worker.kill(True, 10) worker.kill(False) worker.kill() ``` -------------------------------- ### ConcurrentProcessing _length Examples Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/concurrent-processing.mdx Shows how to specify the dataset length for ConcurrentProcessing. The _length can be a fixed integer or a function that returns the length. ```python from thread import ConcurrentProcessing dataset: MyDatasetType = ... ConcurrentProcessing( function = my_function, dataset = dataset, _length = 5, ) def get_length(dataset: MyDatasetType) -> int: ... ConcurrentProcessing( function = my_function, dataset = dataset, _length = get_length, ) ``` -------------------------------- ### thread.Thread.start() Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/thread-class.mdx Starts the execution of the thread. This method should be called on a thread object to begin its operation. It does not take any arguments and returns None. ```python import thread worker = thread.Thread(target = my_target) worker.start() ``` -------------------------------- ### Retrieving Return Values Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/concurrent-processing.mdx Illustrates how to get the results from the processed data, waiting for completion if necessary. ```python import thread worker = thread.ConcurrentProcessing(function = my_func, dataset = [1, 2, 3]) worker.get_return_values() ``` -------------------------------- ### Threaded Functions using Decorator Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/learn/examples/threading.mdx Shows how to use the `@thread.threaded` decorator to automatically run a function in a new thread whenever it's called. This simplifies background task execution. ```python import time import thread @thread.threaded def my_background_task(): time.wait(5) print('My background task is complete.') worker = my_background_task() print('Started background task.') worker.join() # Terminal output: # > Started background task. # > My background task is complete. ``` -------------------------------- ### Linting with Ruff, Eslint, and Prettier Source: https://github.com/python-thread/thread/blob/main/CONTRIBUTING.md Commands to lint and fix code quality issues using Ruff, Eslint, and Prettier. Ensures code consistency and adherence to style guides. ```sh # To lint your code, run: npm run lint # To fix any linting errors, run: npm run lint:fix ``` -------------------------------- ### thread.Thread.start() Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/thread-class.mdx Starts the execution of the thread. This method should be called on a thread object to begin its operation. It does not take any arguments and returns None. It can raise a ThreadStillRunningError if the thread is already running. ```python import thread worker = thread.Thread(target = my_target) worker.start() ``` -------------------------------- ### VersionLink Component Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/index.mdx A React component for creating clickable links, which can open in a new tab if the href starts with 'http'. It supports different visual variants and custom class names. ```jsx import Link from "next/link"; import { ExternalLinkIcon } from "@radix-ui/react-icons"; import { cn } from "@utils"; export const linkVariant = { default: cn( "bg-neutral-100 dark:bg-neutral-800 hover:bg-neutral-200 dark:hover:bg-neutral-700 border border-neutral-300 dark:border-neutral-700", ), }; export function VersionLink({ variant = "default", className, href, ...props }) { return ( ); } ``` -------------------------------- ### ConcurrentProcessing with Lambda Function Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/concurrent-processing.mdx Illustrates using a lambda function as the target for ConcurrentProcessing. While functional, it's recommended to use a standard function for better type hinting and maintainability by linters and IDEs. The example shows starting, joining, and accessing results. ```python from thread import ConcurrentProcessing worker = ConcurrentProcessing(function = lambda x: x + 1, dataset = [1, 2, 3]) worker.start() worker.join() worker.results ``` -------------------------------- ### ConcurrentProcessing Initialization Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/concurrent-processing.mdx Demonstrates how to initialize the ConcurrentProcessing class with a function and a dataset. It shows both direct initialization and using keyword arguments, recommending the latter for clarity. The function argument should accept data from the dataset and return a value. ```python import thread thread.ConcurrentProcessing(lambda x: x + 1, []) thread.ConcurrentProcessing(function = lambda x: x + 1, dataset = []) ``` -------------------------------- ### On-Demand ConcurrentProcessing Initialization Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/concurrent-processing.mdx Demonstrates the recommended and alternative ways to initialize a ConcurrentProcessing object by passing the processing function and dataset. ```python def my_data_processor(Data_In) -> Data_Out: ... # Recommended way my_processor = ConcurrentProcessing( function = my_data_processor, dataset = [i in range(0, n)] ) # OR # Not the recommended way my_processor = ConcurrentProcessing(my_data_processor, [i in range(0, n)]) ``` -------------------------------- ### On-Demand ParallelProcessing Initialization (Python) Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/parallel-processing.mdx Demonstrates the recommended and alternative ways to initialize a ParallelProcessing object with a function and dataset. ```python def my_data_processor(Data_In) -> Data_Out: ... # Recommended way my_processor = ParallelProcessing( function = my_data_processor, dataset = [i in range(0, n)] ) # OR # Not the recommended way my_processor = ParallelProcessing(my_data_processor, [i in range(0, n)]) my_processor.start() ``` -------------------------------- ### ParallelProcessing Initialization with Lambda Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/parallel-processing.mdx Demonstrates initializing ParallelProcessing with a lambda function for simple operations. It shows basic usage and the recommended keyword argument approach. ```python import thread thread.ParallelProcessing(lambda x: x + 1, []) thread.ParallelProcessing(function = lambda x: x + 1, dataset = []) ``` -------------------------------- ### Importing Icons and Components Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/learn/cautions.mdx Imports necessary icons from '@radix-ui/react-icons' and Card/Cards components from 'nextra/components' for UI rendering. ```javascript import { LightningBoltIcon, GridIcon } from "@radix-ui/react-icons"; import { Card, Cards } from "nextra/components"; ``` -------------------------------- ### Importing Thread Settings Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/configuration.mdx Demonstrates how to import the Settings class from the thread library to manage configuration. ```python from thread import Settings ``` -------------------------------- ### Thread CLI Parallel Processing - Module Import Example Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/command-line-interface.mdx Example of using the 'thread process' command to process lines from a CSV file using a function imported from a Python module. ```sh thread process 'clean_data:clean' './dirty_data.csv' ``` ```py import thread from .clean_data import clean # Read files with open('./dataset.csv', 'r') as dataset: data = dataset.readlines() # Starts processing worker = thread.ParallelProcessing( function = clean, dataset = data, ) worker.start() worker.join() # Writes to "output.json" with open('./output.json', 'w') as output: output.write(worker.results) ``` -------------------------------- ### Project Releases Overview Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/index.mdx Displays a list of project releases with version numbers and status badges. Includes links to specific release documentation and indicates the latest stable version. ```jsx
Latest v2.0.5
This is the latest ***stable*** release.
latest stable
v1.1.1
This is the last ***stable*** v1.1.1 release.
stable

Development

Now

dev

Release v2.0.5

14 July 2024

stable

Release v2.0.4

7 July 2024

stable

Release v2.0.3

27 May 2024

stable

Release v2.0.2

25 May 2024

stable

Release v2.0.1

28 April 2024

stable

Release v2.0.0

21 April 2024

stable

Release v1.1.1

17 March 2024

``` -------------------------------- ### HookRuntimeError Example Traceback Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/exceptions.mdx Provides an example traceback for `HookRuntimeError`, which is raised when hooks encounter exceptions. The format shows the hook name, file path, line number, and the specific exception raised, adhering to suppression and ignore rules. ```text HookRuntimeError: Encountered runtime errors in hooks 1. my_function >>>>>>>>>> /usr/home/proj/main.py:50 ZeroDivisionError: <<<<<<<<<< 2. my_otherfunction >>>>>>>>>> ImportError: <<<<<<<<<< ``` -------------------------------- ### Importing Thread Settings Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/configuration.mdx Demonstrates how to import the Settings class from the thread library to manage configuration. ```python from thread import Settings ``` -------------------------------- ### HookRuntimeError Example Traceback Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/exceptions.mdx Provides an example traceback for `HookRuntimeError`, which is raised when hooks encounter exceptions. The format shows the hook name, file path, line number, and the specific exception raised, adhering to suppression and ignore rules. ```text HookRuntimeError: Encountered runtime errors in hooks 1. my_function >>>>>>>>>> /usr/home/proj/main.py:50 ZeroDivisionError: <<<<<<<<<< 2. my_otherfunction >>>>>>>>>> ImportError: <<<<<<<<<< ``` -------------------------------- ### Thread Initialization Arguments Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/thread-class.mdx Details the 'target' argument for the Thread class, including how to pass functions, arguments, and access return values. ```python import thread thread.Thread(lambda x: x + 1) thread.Thread(target = lambda x: x + 1) from thread import Thread def my_target(x: int) -> int: return x + 1 worker = Thread(target = my_target) worker.start() worker.join() worker.result # This will be inferred as int ``` -------------------------------- ### Thread Initialization Arguments Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/thread-class.mdx Details the 'target' argument for the Thread class, including how to pass functions, arguments, and access return values. ```python import thread thread.Thread(lambda x: x + 1) thread.Thread(target = lambda x: x + 1) from thread import Thread def my_target(x: int) -> int: return x + 1 worker = Thread(target = my_target) worker.start() worker.join() worker.result # This will be inferred as int ``` -------------------------------- ### Displaying Cautions with Cards Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/learn/cautions.mdx Uses Nextra's Card and Cards components to display a list of cautions, each with a title, link, and an associated icon. ```html } /> } /> ``` -------------------------------- ### Thread CLI Documentation Command Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/command-line-interface.mdx Opens the documentation file in the browser or prints the link if it fails. ```sh thread docs ``` -------------------------------- ### Importing the Thread Class Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/thread-class.mdx Demonstrates different ways to import the Thread class from the thread library. ```python import thread thread.Thread from thread import Thread ``` -------------------------------- ### Importing the Thread Class Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/thread-class.mdx Demonstrates different ways to import the Thread class from the thread library. ```python import thread thread.Thread from thread import Thread ``` -------------------------------- ### Thread CLI Help Command Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/command-line-interface.mdx Opens the issue tracker in the browser or prints the link if it fails. ```sh thread help ``` -------------------------------- ### Thread CLI Configuration Command Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/command-line-interface.mdx Placeholder for the configuration command, which is coming soon. ```sh thread config ``` -------------------------------- ### ConcurrentProcessing _get_value Example Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/concurrent-processing.mdx Demonstrates how to provide a custom _get_value function for retrieving data from a dataset within ConcurrentProcessing. This function is invoked each time a value is retrieved. ```python from thread import ConcurrentProcessing dataset: MyDatasetType = ... ConcurrentProcessing( function = my_function, dataset = dataset, _get_value = lambda d, index: d[index], ) ConcurrentProcessing( function = my_function, dataset = dataset, _get_value = lambda d, index: d.getIndex(index), ) ``` -------------------------------- ### ParallelProcessing.is_alive() Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/parallel-processing.mdx Checks if the threads managed by ParallelProcessing are currently running. This method returns a boolean indicating the status and can raise ThreadNotInitializedError if the process hasn't started. ```python import thread worker = thread.ParallelProcessing(function = my_func, dataset = [1, 2, 3]) worker.is_alive() ``` -------------------------------- ### Thread CLI Report Command Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/command-line-interface.mdx Opens the documentation file in the browser or prints the link if it fails. ```sh thread report ``` -------------------------------- ### Thread CLI Documentation Command Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/command-line-interface.mdx Opens the documentation in a web browser or prints the link if the browser cannot be opened. ```sh thread docs ``` -------------------------------- ### ParallelProcessing.start() Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/parallel-processing.mdx Starts the parallel processing of a dataset using a specified function. This method is invoked on an instance of ParallelProcessing. It may raise a ThreadStillRunningError if the thread is already active. ```python import thread worker = thread.ParallelProcessing(function = my_func, dataset = [1, 2, 3]) worker.start() ``` -------------------------------- ### React Components for Documentation Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/parallel-processing.mdx Includes various React components used within the Nextra documentation framework for rendering elements like callouts, steps, and tabs. ```javascript import { cn } from "@utils"; import { Callout, Steps, Tabs } from "nextra/components"; import { CheckIcon, Cross2Icon, DotFilledIcon } from "@radix-ui/react-icons"; import { Statuses, ThreadStatuses, ThreadExceptions, } from "@components/typedata"; export function ArgumentWrapper({ children, className, ...props }) { return (
{children}
); } export function ArgumentBody({ children, className, ...props }) { return (
{children}
); } export function ArgumentExtra({ children, className, ...props }) { return ( {children} ); } export function TabbedData({ type, keys = [] }) { return ( {keys.map((key, i) => ( {type === "status" ? ThreadStatuses[key] : ThreadExceptions[key]} ))} ); } export function Text({ children, className, ...props }) { return (

{children}

); } ``` -------------------------------- ### Testing with Pytest and npm Source: https://github.com/python-thread/thread/blob/main/CONTRIBUTING.md Commands to run tests for the project. It supports both Pytest for Python code and npm for other project dependencies. ```sh # To test your code, run: npm test # Or pytest -sv . ``` -------------------------------- ### Initializing a Thread (Decorated Function) Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/thread-class.mdx Explains how to use the @thread.threaded decorator to automatically run a function in a new thread. ```python import thread @thread.threaded def my_target(): ... worker = my_target() # thread.Thread() ``` -------------------------------- ### Initializing a Thread (Decorated Function) Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/v1/thread-class.mdx Explains how to use the @thread.threaded decorator to automatically run a function in a new thread. ```python import thread @thread.threaded def my_target(): ... worker = my_target() # thread.Thread() ``` -------------------------------- ### Type-Annotated Thread Function Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/learn/examples/threading.mdx Illustrates how to use Python's type annotations with the `thread` library for functions running in separate threads. This enhances code readability and helps catch type errors early. ```python import thread def background_function(x: int) -> int: return x + 1 worker = Thread(target=background_function, args=(5,)) worker.start() returned = worker.get_return_value() # int ``` -------------------------------- ### ConcurrentProcessing Methods Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/concurrent-processing.mdx This section documents the methods of the ConcurrentProcessing class, which are used to manage and control the execution of threads for concurrent processing. It covers starting threads, checking their status, retrieving results, waiting for completion, and terminating them. ```APIDOC ConcurrentProcessing: start() -> None Description: Starts the concurrent processing. Usage: worker.start() Exceptions Raised: ThreadStillRunningError is_alive() -> bool Description: Checks if the threads are still alive. Usage: worker.is_alive() Exceptions Raised: ThreadNotInitializedError get_return_values() -> List[Data_Out] Description: Halts thread execution until processing completes and returns the value returned by the function. Usage: worker.get_return_values() Exceptions Raised: ThreadNotInitializedError, ThreadNotRunningError join(timeout: float = None) -> None Description: Halts thread execution until the ConcurrentProcessing completes or exceeds the timeout. A None value for timeout is equivalent to float("inf"). Usage: worker.join(5) Exceptions Raised: ThreadNotInitializedError, ThreadNotRunningError kill(yielding: bool = False, timeout: float = 5) -> bool Description: Schedules threads to be killed. If yielding is True, halts execution until threads are killed or timeout is exceeded. A None value for timeout is equivalent to float("inf"). Usage: worker.kill(True, 10) Exceptions Raised: ThreadNotInitializedError, ThreadNotRunningError Warning: Only schedules threads to be killed; does not immediately kill them. Killing occurs after the current line of execution in the target thread. ``` -------------------------------- ### Decorated Functions for Background Processing Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/learn/examples/processing.mdx Illustrates using the `@thread.processor` decorator to automatically run functions in separate threads. When a decorated function is called, it spawns a new thread and runs in the background. The example shows how to join the worker and retrieve results. ```python import time import thread @thread.processor def my_processor(x): time.wait(5) print('My processing task is complete.') return x worker = my_background_task([1, 2, 3]) print('Started processing task.') worker.join() worker.get_return_values() # [1, 2, 3] # Terminal output: # > Started processing task. # > My processing task is complete. ``` -------------------------------- ### Thread CLI Help Command Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/command-line-interface.mdx Opens the issue tracker in a web browser or prints the link if the browser cannot be opened. ```sh thread help ``` -------------------------------- ### Thread CLI Configuration Command Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/docs/latest/command-line-interface.mdx Placeholder command for future configuration options. ```sh thread config ``` -------------------------------- ### Feature Component (React) Source: https://github.com/python-thread/thread/blob/main/docs/src/pages/index.mdx A React component designed to display features with a title, description, optional version, and a 'Read More' link. It includes dynamic styling for a gradient background effect on hover. ```javascript export function Feature({ title, description, version = false, href = false, ...props }) { return (
{version ? (

{version}

) : (
)}

{title}

{description}

{href && ( Read More )}
); } ```