Skip to main content

======================================


.. image:: https://readthedocs.org/projects/attentive/badge/?version=latest
:target: http://attentive.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status


.. image:: https://github.com/sthysel/attentive/blob/master/docs/attentive.jpg?raw=true


.. code:: python


from attentive import StoppableThread, quit
from random import randint


class Man(StoppableThread):
def __init__(self, name):
StoppableThread.__init__(self)
self.name = name

def run(self):
print('{} has quickened'.format(self.name))
while not self.stopped:
self.sleep(randint(1, 10))
print('{} throws a {}'.format(self.name, randint(1, 6)))

print('{} expires'.format(self.name))


with Man('Trump'), Man('Wang'), Man('Erdoğan'):
while not quit.is_set():
quit.wait(1)



Example Run
***********

.. code:: bash


🚼Trump has quickened
🚼Wang has quickened
🚼Erdoğan has quickened
Wang throws a ☣
Trump throws a ☢
Erdoğan throws a ☣
Wang throws a ☣
Wang throws a ☣
Erdoğan throws a 🍭
Erdoğan throws a ☣
Trump throws a ☣
^CErdoğan throws a 🍼
☠ Erdoğan expires
Wang throws a ☣
☠ Wang expires
Trump throws a 🍼
☠ Trump expires



Use ``attentive`` if you need to wire up a some worker threads that needs to cleanly
shut themselves down on a SIG_INT or SIG_TERM.

``StoppableThread`` is a context managed thread that lives on while in context. Once it exists
context it sets its internal stopped flag that are periodically checked for state. This signals
thread state allowing the thread to cleanly exit.

External state is controlled by a signal event, exiting the main context loop.

Internally use the StoppableThread.sleep() method that is interrupted when stop()ed during
sleep.

Install
=======

Install from pypi

.. code::

$ pip install attentive

Install from source

.. code::

$ pip install .



Versioning
==========

Current version is 0.1.5


Metadata

Release files for attentive 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for attentive 0.1.5
File Interpreter ABI Platform
attentive-0.1.5-py2.py3-none-any.whl Python 3, Python 2 none any Details

Release files / attentive-0.1.5-py2.py3-none-any.whl

Download URL attentive-0.1.5-py2.py3-none-any.whl
Size 5.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
debe72dfd915d569ec5aaa2bd0699daa91b09730de49030c0460768a7f4381bf
BLAKE2b-256 checksum
How to use checksums
b15f0422494cf88c5255d059897f674a6897f42b80b35a2f194852dfebcd06bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.5 This release

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page