Skip to main content

System-wide Event synchonization for posix (emulating the threading.Event api)

Project description

Introduction

SystemEvent provides a simple synchronization primitive for use across multiple processes. The SystemEvent object emulates the threading.Event API exactly. In addition, simple scripts (evt_set, evt_wait, and evt_clear) are installed for easy usage from shell scripts.

The main reason to use SystemEvent is in situations when you want processes to wait on other processes without the need for polling.

Installation

pip install SystemEvent

Usage

SystemEvent uses named posix semaphores under the hood, so you need to choose event names that are unique to your application. Any event references will use this unique name.

>From Python, use it exactly like you would use a threading.Event instances, with the main difference being that you need to give your event a name so that other processes can reference it.

For example, in as many consoles as you like, set up an event and have it wait (the last line will block on each `wait() call):

>>> import SystemEvent
>>> evt = SystemEvent.SystemEvent("my_event")
>>> evt.wait()

Alternatively, you can just run evt_wait my_event from your favorite shell (this is just a small script that does the above almost exactly).

In another console, set the event and note that the first event releases:

>>> import SystemEvent
>>> evt = SystemEvent.SystemEvent("my_event")
>>> evt.set()

All events blocking on “my_event” will be immediately released by this set() call. Subsequent calls to evt.wait() from any process will not block, since the event is now globally latched.

To clear the event (so that calls to evt.wait() will block again), call evt.clear().

As with threading.Event (and multiprocessing.Event) there is also an isSet() method which tells you the current state (but watch out for race conditions when checking it).

Shell scripts

Three shell scripts are provided, with the following usage:

evt_wait <event_name> [timeout_s]

evt_set <event_name>

evt_clear <event_name>

These scripts are thin shells over SystemEvent usage. The timeout_s option on evt_wait is optional, and defaults to infinity.

All scripts have an exit code of 0, unless evt_wait times out, in which case it returns 1.

How does it work?

SystemEvent currently uses a posix semaphore internally. To integrate with other non-python applications, you can just access the same named semaphore. Just be careful that you increment and decrement correctly. Check out the code for details… it is ridiculously small.

License

MIT. See LICENSE file.

TODO

  1. Add tests

  2. Make it work in Windows, too

  3. Remove the posix_ipc requirement

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

SystemEvent-1.0.1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

SystemEvent-1.0.1-py2-none-any.whl (6.8 kB view details)

Uploaded Python 2

File details

Details for the file SystemEvent-1.0.1.tar.gz.

File metadata

  • Download URL: SystemEvent-1.0.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for SystemEvent-1.0.1.tar.gz
Algorithm Hash digest
SHA256 c1240745a26083506f989a7a1bb60aae9636909669603dd0d259a4fc8d2e45c6
MD5 ebd93aacde7e1177ecfae861b9dd54bd
BLAKE2b-256 b8e71be6904240974fa79bf6d6b1e7927bebbdb119de3cc5b1d010b5bdbd447b

See more details on using hashes here.

File details

Details for the file SystemEvent-1.0.1-py2-none-any.whl.

File metadata

File hashes

Hashes for SystemEvent-1.0.1-py2-none-any.whl
Algorithm Hash digest
SHA256 2b670144a480fac3f7d0ad1112109efb30d6dacf2ed95f06536c675b0309e84c
MD5 4955e340d81527d969fccdcd31aa283d
BLAKE2b-256 05e1f174dfbcab4cf61a21d520c8d1d8f8a5326754a572596c72d3a94647c472

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page