Metadata-Version: 2.1
Name: save-thread-result
Version: 0.1.1.post1
Summary: Simple subclass wrapper around `threading.Thread` to get the return value from a thread in python. Exact same interface as `threading.Thread`! 🌟 Star this repo if you found it useful! 🌟
Home-page: https://github.com/slow-but-steady/save-thread-result/tree/main/python
Author: slow-but-steady
Author-email: slowbutsteady1234@gmail.com
License: MIT License
Project-URL: Bug Reports, https://github.com/slow-but-steady/save-thread-result/issues
Project-URL: PyPi Funding, https://donate.pypi.org
Project-URL: Source, https://github.com/slow-but-steady/save-thread-result/tree/main/python
Project-URL: Pull requests, https://github.com/slow-but-steady/save-thread-result/pulls
Project-URL: Issues, https://github.com/slow-but-steady/save-thread-result/issues
Project-URL: Code, https://github.com/slow-but-steady/save-thread-result/tree/main/python
Keywords: threading thread multi-threading logging logger archiving tracing tracer debugging debugger automation csv txt markdown md YouTube videos URL scraping Selenium macos windows linux
Platform: UNKNOWN
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: MacOS X
Classifier: Environment :: No Input/Output (Daemon)
Classifier: Environment :: OpenStack
Classifier: Environment :: Other Environment
Classifier: Environment :: Plugins
Classifier: Environment :: Web Environment
Classifier: Environment :: Web Environment :: Buffet
Classifier: Environment :: Web Environment :: Mozilla
Classifier: Environment :: Web Environment :: ToscaWidgets
Classifier: Environment :: Win32 (MS Windows)
Classifier: Environment :: X11 Applications
Classifier: Environment :: X11 Applications :: GTK
Classifier: Environment :: X11 Applications :: Gnome
Classifier: Environment :: X11 Applications :: KDE
Classifier: Environment :: X11 Applications :: Qt
Classifier: Framework :: AsyncIO
Classifier: Framework :: Django
Classifier: Framework :: Flask
Classifier: Framework :: IDLE
Classifier: Framework :: IPython
Classifier: Framework :: Jupyter
Classifier: Framework :: Pyramid
Classifier: Framework :: Pytest
Classifier: Framework :: Robot Framework
Classifier: Framework :: Robot Framework :: Library
Classifier: Framework :: Robot Framework :: Tool
Classifier: Framework :: Scrapy
Classifier: Framework :: Setuptools Plugin
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Intended Audience :: Healthcare Industry
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: Legal Industry
Classifier: Intended Audience :: Manufacturing
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: System Administrators
Classifier: Intended Audience :: Telecommunications Industry
Classifier: License :: Free For Educational Use
Classifier: License :: Free For Home Use
Classifier: License :: Free for non-commercial use
Classifier: License :: Freely Distributable
Classifier: License :: Freeware
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Operating System :: Android
Classifier: Operating System :: BeOS
Classifier: Operating System :: MacOS
Classifier: Operating System :: MacOS :: MacOS 9
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: Microsoft
Classifier: Operating System :: Microsoft :: MS-DOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: Microsoft :: Windows :: Windows 10
Classifier: Operating System :: Microsoft :: Windows :: Windows 3.1 or Earlier
Classifier: Operating System :: Microsoft :: Windows :: Windows 7
Classifier: Operating System :: Microsoft :: Windows :: Windows 8
Classifier: Operating System :: Microsoft :: Windows :: Windows 8.1
Classifier: Operating System :: Microsoft :: Windows :: Windows 95/98/2000
Classifier: Operating System :: Microsoft :: Windows :: Windows CE
Classifier: Operating System :: Microsoft :: Windows :: Windows NT/2000
Classifier: Operating System :: Microsoft :: Windows :: Windows Server 2003
Classifier: Operating System :: Microsoft :: Windows :: Windows Server 2008
Classifier: Operating System :: Microsoft :: Windows :: Windows Vista
Classifier: Operating System :: Microsoft :: Windows :: Windows XP
Classifier: Operating System :: OS Independent
Classifier: Operating System :: OS/2
Classifier: Operating System :: Other OS
Classifier: Operating System :: PDA Systems
Classifier: Operating System :: POSIX
Classifier: Operating System :: POSIX :: AIX
Classifier: Operating System :: POSIX :: BSD
Classifier: Operating System :: POSIX :: BSD :: BSD/OS
Classifier: Operating System :: POSIX :: BSD :: FreeBSD
Classifier: Operating System :: POSIX :: BSD :: NetBSD
Classifier: Operating System :: POSIX :: BSD :: OpenBSD
Classifier: Operating System :: POSIX :: GNU Hurd
Classifier: Operating System :: POSIX :: HP-UX
Classifier: Operating System :: POSIX :: IRIX
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: POSIX :: Other
Classifier: Operating System :: POSIX :: SCO
Classifier: Operating System :: POSIX :: SunOS/Solaris
Classifier: Operating System :: PalmOS
Classifier: Operating System :: Unix
Classifier: Operating System :: iOS
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.0
Classifier: Programming Language :: Python :: 3.1
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.2
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Topic :: Adaptive Technologies
Classifier: Topic :: Communications
Classifier: Topic :: Communications :: BBS
Classifier: Topic :: Communications :: Chat
Classifier: Topic :: Communications :: Chat :: ICQ
Classifier: Topic :: Communications :: Chat :: Internet Relay Chat
Classifier: Topic :: Communications :: Chat :: Unix Talk
Classifier: Topic :: Communications :: Conferencing
Classifier: Topic :: Communications :: Email
Classifier: Topic :: Communications :: Email :: Address Book
Classifier: Topic :: Communications :: Email :: Email Clients (MUA)
Classifier: Topic :: Communications :: Email :: Filters
Classifier: Topic :: Communications :: Email :: Mail Transport Agents
Classifier: Topic :: Communications :: Email :: Mailing List Servers
Classifier: Topic :: Communications :: Email :: Post-Office
Classifier: Topic :: Communications :: Email :: Post-Office :: IMAP
Classifier: Topic :: Communications :: Email :: Post-Office :: POP3
Classifier: Topic :: Communications :: FIDO
Classifier: Topic :: Communications :: Fax
Classifier: Topic :: Communications :: File Sharing
Classifier: Topic :: Communications :: Ham Radio
Classifier: Topic :: Communications :: Internet Phone
Classifier: Topic :: Communications :: Telephony
Classifier: Topic :: Communications :: Usenet News
Classifier: Topic :: Database
Classifier: Topic :: Desktop Environment
Classifier: Topic :: Documentation
Classifier: Topic :: Education
Classifier: Topic :: Education :: Testing
Classifier: Topic :: Games/Entertainment
Classifier: Topic :: Games/Entertainment :: Arcade
Classifier: Topic :: Games/Entertainment :: Board Games
Classifier: Topic :: Games/Entertainment :: First Person Shooters
Classifier: Topic :: Games/Entertainment :: Fortune Cookies
Classifier: Topic :: Games/Entertainment :: Multi-User Dungeons (MUD)
Classifier: Topic :: Games/Entertainment :: Puzzle Games
Classifier: Topic :: Games/Entertainment :: Real Time Strategy
Classifier: Topic :: Games/Entertainment :: Role-Playing
Classifier: Topic :: Games/Entertainment :: Side-Scrolling/Arcade Games
Classifier: Topic :: Games/Entertainment :: Simulation
Classifier: Topic :: Games/Entertainment :: Turn Based Strategy
Classifier: Topic :: Home Automation
Classifier: Topic :: Internet
Classifier: Topic :: Internet :: File Transfer Protocol (FTP)
Classifier: Topic :: Internet :: Finger
Classifier: Topic :: Internet :: Log Analysis
Classifier: Topic :: Internet :: Name Service (DNS)
Classifier: Topic :: Internet :: Proxy Servers
Classifier: Topic :: Internet :: WAP
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: WWW/HTTP :: Browsers
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content :: CGI Tools/Libraries
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content :: Content Management System
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content :: Message Boards
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content :: News/Diary
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content :: Page Counters
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content :: Wiki
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
Classifier: Topic :: Internet :: WWW/HTTP :: Session
Classifier: Topic :: Internet :: WWW/HTTP :: Site Management
Classifier: Topic :: Internet :: WWW/HTTP :: Site Management :: Link Checking
Classifier: Topic :: Internet :: WWW/HTTP :: WSGI
Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Application
Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Middleware
Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Server
Classifier: Topic :: Internet :: XMPP
Classifier: Topic :: Internet :: Z39.50
Classifier: Topic :: Multimedia
Classifier: Topic :: Multimedia :: Graphics
Classifier: Topic :: Multimedia :: Graphics :: 3D Modeling
Classifier: Topic :: Multimedia :: Graphics :: 3D Rendering
Classifier: Topic :: Multimedia :: Graphics :: Capture
Classifier: Topic :: Multimedia :: Graphics :: Capture :: Digital Camera
Classifier: Topic :: Multimedia :: Graphics :: Capture :: Scanners
Classifier: Topic :: Multimedia :: Graphics :: Capture :: Screen Capture
Classifier: Topic :: Multimedia :: Graphics :: Editors
Classifier: Topic :: Multimedia :: Graphics :: Editors :: Raster-Based
Classifier: Topic :: Multimedia :: Graphics :: Editors :: Vector-Based
Classifier: Topic :: Multimedia :: Graphics :: Graphics Conversion
Classifier: Topic :: Multimedia :: Graphics :: Presentation
Classifier: Topic :: Multimedia :: Graphics :: Viewers
Classifier: Topic :: Multimedia :: Sound/Audio
Classifier: Topic :: Multimedia :: Sound/Audio :: Analysis
Classifier: Topic :: Multimedia :: Sound/Audio :: CD Audio
Classifier: Topic :: Multimedia :: Sound/Audio :: CD Audio :: CD Playing
Classifier: Topic :: Multimedia :: Sound/Audio :: CD Audio :: CD Ripping
Classifier: Topic :: Multimedia :: Sound/Audio :: CD Audio :: CD Writing
Classifier: Topic :: Multimedia :: Sound/Audio :: Capture/Recording
Classifier: Topic :: Multimedia :: Sound/Audio :: Conversion
Classifier: Topic :: Multimedia :: Sound/Audio :: Editors
Classifier: Topic :: Multimedia :: Sound/Audio :: MIDI
Classifier: Topic :: Multimedia :: Sound/Audio :: Mixers
Classifier: Topic :: Multimedia :: Sound/Audio :: Players
Classifier: Topic :: Multimedia :: Sound/Audio :: Players :: MP3
Classifier: Topic :: Multimedia :: Sound/Audio :: Sound Synthesis
Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
Classifier: Topic :: Multimedia :: Video
Classifier: Topic :: Multimedia :: Video :: Capture
Classifier: Topic :: Multimedia :: Video :: Conversion
Classifier: Topic :: Multimedia :: Video :: Display
Classifier: Topic :: Multimedia :: Video :: Non-Linear Editor
Classifier: Topic :: Office/Business
Classifier: Topic :: Office/Business :: Financial
Classifier: Topic :: Office/Business :: Financial :: Accounting
Classifier: Topic :: Office/Business :: Financial :: Investment
Classifier: Topic :: Office/Business :: Scheduling
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: Artificial Life
Classifier: Topic :: Scientific/Engineering :: Astronomy
Classifier: Topic :: Scientific/Engineering :: Atmospheric Science
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Classifier: Topic :: Scientific/Engineering :: Chemistry
Classifier: Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)
Classifier: Topic :: Scientific/Engineering :: GIS
Classifier: Topic :: Scientific/Engineering :: Human Machine Interfaces
Classifier: Topic :: Scientific/Engineering :: Image Processing
Classifier: Topic :: Scientific/Engineering :: Image Recognition
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
Classifier: Topic :: Scientific/Engineering :: Physics
Classifier: Topic :: Scientific/Engineering :: Visualization
Classifier: Topic :: Security
Classifier: Topic :: Security :: Cryptography
Classifier: Topic :: Software Development
Classifier: Topic :: Software Development :: Bug Tracking
Classifier: Topic :: Software Development :: Build Tools
Classifier: Topic :: Software Development :: Debuggers
Classifier: Topic :: Software Development :: Embedded Systems
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Software Development :: Testing
Classifier: Topic :: Software Development :: Testing :: Acceptance
Classifier: Topic :: Software Development :: Testing :: BDD
Classifier: Topic :: Software Development :: Testing :: Mocking
Classifier: Topic :: Software Development :: Testing :: Traffic Generation
Classifier: Topic :: Software Development :: Testing :: Unit
Classifier: Topic :: Software Development :: Version Control :: Git
Classifier: Topic :: System
Classifier: Topic :: System :: Benchmark
Classifier: Topic :: System :: Boot
Classifier: Topic :: System :: Boot :: Init
Classifier: Topic :: System :: Distributed Computing
Classifier: Topic :: System :: Filesystems
Classifier: Topic :: System :: Hardware
Classifier: Topic :: System :: Logging
Classifier: Topic :: System :: Monitoring
Classifier: Topic :: System :: Networking
Classifier: Topic :: System :: Networking :: Firewalls
Classifier: Topic :: System :: Networking :: Monitoring
Classifier: Topic :: System :: Networking :: Time Synchronization
Classifier: Topic :: System :: Operating System
Classifier: Topic :: System :: Power (UPS)
Classifier: Topic :: System :: Recovery Tools
Classifier: Topic :: System :: Shells
Classifier: Topic :: System :: Software Distribution
Classifier: Topic :: System :: System Shells
Classifier: Topic :: System :: Systems Administration
Classifier: Topic :: System :: Systems Administration :: Authentication/Directory
Classifier: Topic :: Terminals
Classifier: Topic :: Utilities
Requires-Python: >=3, <4
Description-Content-Type: text/markdown

# Python API

## Quickstart

Installing the `save_thread_result` module:
```
pip3 install -U save-thread-result     # MacOS/Linux
pip  install -U save-thread-result     # Windows

# if that doesn't work:
python3 -m pip install -U save-thread-result     # MacOS/Linux
python  -m pip install -U save-thread-result     # Windows
```

Using the `ThreadWithResult` class from the `save_thread_result` module:
```
from save_thread_result import ThreadWithResult


# As of Release 0.0.3, you can also specify values for
# `group`, `name`, and `daemon` if you want to set those
# values manually.

thread = ThreadWithResult(
    target = my_function,
    args   = (my_function_arg1, my_function_arg2, ...)
    kwargs = {my_function_kwarg1: kwarg1_value, my_function_kwarg2: kwarg2_value, ...}
)

thread.start()
thread.join()
if getattr(thread, 'result', None):
    print(thread.result)
else:
    # thread.result attribute not set - something caused
    # the thread to terminate BEFORE the thread finished
    # executing the function passed in through the
    # `target` argument
    print('ERROR! Something went wrong while executing this thread, and the function you passed in did NOT complete!!')
```

Reading the documentation for more information:
```
from save_thread_result import ThreadWithResult
help(ThreadWithResult)
```

## Short explanation

This module uses a [`threading.Thread`](https://docs.python.org/3/library/threading.html#threading.Thread) subclass `ThreadWithResult` that saves the result of a thread (from [`threading`](https://docs.python.org/3/library/threading.html) built-in module in the [Python Standard library](https://docs.python.org/3/library/index.html)) as its `result` attribute - i.e. after the thread finishes running, call `thread.result` to get the return value from the function that ran on that thread.

## Examples

Dummy example:
```
from save_thread_result import ThreadWithResult

import time, random, threading


def function_to_thread(n):
    count = 0
    while count < 3:
            print(f'Still running {threading.current_thread().name}...')
            count +=1
            time.sleep(3)
    result = random.random()
    print(f'Return value of {threading.current_thread().name} should be: {result}')
    return result


def main():
    thread1 = ThreadWithResult(target=function_to_thread, args=(1,))
    thread2 = ThreadWithResult(target=function_to_thread, args=(2,))
    thread1.start()
    thread2.start()
    thread1.join()
    thread2.join()
    print(f'The `result` attribute of {thread1.name} is: {thread1.result}')
    print(f'The `result` attribute of {thread2.name} is: {thread2.result}')

main()
```

<details>
  <summary><b>More information</b></summary>

  <details>
    <summary><b>Sources I looked at before creating the custom class</b></summary>

  - [Return value from thread](https://stackoverflow.com/questions/1886090/return-value-from-thread)
  - [Threading in python: retrieve return value when using target= [duplicate]](https://stackoverflow.com/questions/2577233/threading-in-python-retrieve-return-value-when-using-target)
  - [How to get the return value from a thread in python?](https://stackoverflow.com/questions/6893968/how-to-get-the-return-value-from-a-thread-in-python)
  - [Using Python Threading and Returning Multiple Results (Tutorial)](https://www.shanelynn.ie/using-python-threading-for-multiple-results-queue/)
  - [How to get the return value from a thread using python](https://www.edureka.co/community/31966/how-to-get-the-return-value-from-a-thread-using-python)
  - [How to manage python threads results?](https://stackoverflow.com/questions/3239617/how-to-manage-python-threads-results#3239815)
  - [How to obtain the results from a pool of threads in python?](https://stackoverflow.com/questions/26104512/how-to-obtain-the-results-from-a-pool-of-threads-in-python)
  - [Google search](https://www.google.com/search?hl=en&q=python%20save%20thread%20result)
  </details>
</details>


