Giter Site home page Giter Site logo

attentive's Introduction


Documentation Status

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

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

🚼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

$ pip install attentive

Install from source

$ pip install .

Versioning

Current version is 0.1.5

attentive's People

Contributors

sthysel avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.