Name | timer-event JSON |
Version |
0.9.1
JSON |
| download |
home_page | |
Summary | The package offers thread-safe classes for event-driven programming, including a versatile Event class for managing callback routines and a TimerEvent class for creating repeated timer-based events. |
upload_time | 2023-03-21 05:34:36 |
maintainer | |
docs_url | None |
author | |
requires_python | >=3.6 |
license | |
keywords |
event
thread-safe
event-driven
timer-based events
repeated events
callback
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Timer Event Package
This package provides two classes for working with events:
*1. EventThread:* A class for creating and managing events with callback routines.\
This class can be used independently of TimerEvent for handling general event-driven scenarios without any time-based requirements.
*2. TimerEvent:* A class that extends EventThread to create timer-based events.\
This class is specifically designed for scenarios where events are triggered after a certain period of time or at specific intervals.\
**Note:** Since this class extends the EventThread class it uses most all methods defined and documented in EvenThread class.
## **EventThread:**
The EventThread class creates an event that can be subscribed to and triggered with a payload. The class uses its own thread to broadcast events to subscribers. The callback function is called when the event is triggered with a payload.
The packet dictionary is passed to the callback.\
The packet dictionary includes:
> All parameters passed in during instantiation of the EventThread.\
> Minimum items included: ..\
"event" = The event name\
"dest" = The subscriber name provided when subscribing\
"payload" = The object included in the post\
"cookie" = The cookie if included when subscribing, otherwise None
The EventThread class has the following methods::
subscribe(name: str, on_event: callable): Subscribes to the event with a callback function.
unsubscribe(name: str): Unsubscribes from the event.
post(payload, **kwargs): Posts an event with a payload to the subscribers.
pause(): Pauses broadcasting events
unpause(): Unpauses the event to continue broadcasting events
stop(): Stops the event processing thread, clears the subscribers list.
Note: This can not be used as pause. Once the EventThread instance is stopped it can not be restarted.
A new instance must be created after calling stop to continue eventing, but the subscribers list will be lost.
## **TimerEvent:**
The TimerEvent class creates a timed event that triggers at a specified interval. The class uses a Timer object to initiate the timed event. The TimerEvent class can be subscribed to using the subscribe method, which takes a name and a callback function as arguments. The callback function is executed when the timed event is triggered.
The TimerEvent class has the following methods::
subscribe(name: str, on_event: callable): Subscribes to the timed event with a callback function.
unsubscribe(name: str): Unsubscribes from the timed event.
stop(): Stops the timed event.
## Example Usage::
<code>
from timer_event import TimerEvent, EventThread
import time
# Create a TimerEvent that triggers every 5 seconds
te = TimerEvent(interval=5.0)
# Subscribe to the TimerEvent
def te_on_event(packet):
print("TimerEvent triggered")
te.subscribe(name="test_subscriber", on_event=te_on_event)
# Start the TimerEvent
te.start()
# Create an Event
event = EventThread("test_event")
# Subscribe to the Event
def ev_on_event(payload):
print(f"Event triggered with payload: {payload}")
event.subscribe(name="test_subscriber", on_event=ev_on_event)
# Post an event with a payload
event.post("test_payload")
# Sleep to allow for timer events
time.sleep(10)
# Stop the TimerEvent and Event
te.stop()
event.stop()
</code>
Raw data
{
"_id": null,
"home_page": "",
"name": "timer-event",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "event,thread-safe,event-driven,timer-based events,repeated events,callback",
"author": "",
"author_email": "Erol Yesin <erol@sandboxzilla.net>",
"download_url": "https://files.pythonhosted.org/packages/36/16/c4746ab83746952f6fc2233c8a44fd016f0aab9877c4e2ee6e61dd766f2a/timer_event-0.9.1.tar.gz",
"platform": null,
"description": "# Timer Event Package\n\nThis package provides two classes for working with events:\n\n*1. EventThread:* A class for creating and managing events with callback routines.\\\n This class can be used independently of TimerEvent for handling general event-driven scenarios without any time-based requirements.\n\n*2. TimerEvent:* A class that extends EventThread to create timer-based events.\\\n This class is specifically designed for scenarios where events are triggered after a certain period of time or at specific intervals.\\\n **Note:** Since this class extends the EventThread class it uses most all methods defined and documented in EvenThread class.\n\n## **EventThread:**\n\nThe EventThread class creates an event that can be subscribed to and triggered with a payload. The class uses its own thread to broadcast events to subscribers. The callback function is called when the event is triggered with a payload.\n\nThe packet dictionary is passed to the callback.\\\nThe packet dictionary includes:\n> All parameters passed in during instantiation of the EventThread.\\\n> Minimum items included: ..\\\n \"event\" = The event name\\\n \"dest\" = The subscriber name provided when subscribing\\\n \"payload\" = The object included in the post\\\n \"cookie\" = The cookie if included when subscribing, otherwise None\n\nThe EventThread class has the following methods::\n\n subscribe(name: str, on_event: callable): Subscribes to the event with a callback function.\n unsubscribe(name: str): Unsubscribes from the event.\n post(payload, **kwargs): Posts an event with a payload to the subscribers.\n pause(): Pauses broadcasting events\n unpause(): Unpauses the event to continue broadcasting events\n stop(): Stops the event processing thread, clears the subscribers list.\n Note: This can not be used as pause. Once the EventThread instance is stopped it can not be restarted.\n A new instance must be created after calling stop to continue eventing, but the subscribers list will be lost.\n\n ## **TimerEvent:**\n\nThe TimerEvent class creates a timed event that triggers at a specified interval. The class uses a Timer object to initiate the timed event. The TimerEvent class can be subscribed to using the subscribe method, which takes a name and a callback function as arguments. The callback function is executed when the timed event is triggered.\n\nThe TimerEvent class has the following methods::\n\n subscribe(name: str, on_event: callable): Subscribes to the timed event with a callback function.\n unsubscribe(name: str): Unsubscribes from the timed event.\n stop(): Stops the timed event.\n\n ## Example Usage::\n<code>\n\n from timer_event import TimerEvent, EventThread\n import time\n\n # Create a TimerEvent that triggers every 5 seconds\n te = TimerEvent(interval=5.0)\n\n # Subscribe to the TimerEvent\n def te_on_event(packet):\n print(\"TimerEvent triggered\")\n\n te.subscribe(name=\"test_subscriber\", on_event=te_on_event)\n\n # Start the TimerEvent\n te.start()\n\n # Create an Event\n event = EventThread(\"test_event\")\n\n # Subscribe to the Event\n def ev_on_event(payload):\n print(f\"Event triggered with payload: {payload}\")\n\n event.subscribe(name=\"test_subscriber\", on_event=ev_on_event)\n\n # Post an event with a payload\n event.post(\"test_payload\")\n\n # Sleep to allow for timer events\n time.sleep(10)\n\n # Stop the TimerEvent and Event\n te.stop()\n event.stop()\n</code>\n",
"bugtrack_url": null,
"license": "",
"summary": "The package offers thread-safe classes for event-driven programming, including a versatile Event class for managing callback routines and a TimerEvent class for creating repeated timer-based events.",
"version": "0.9.1",
"split_keywords": [
"event",
"thread-safe",
"event-driven",
"timer-based events",
"repeated events",
"callback"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "17de020b2c2cf995fd9e4c29e5b4fc95eb962630f0b7053a903a8824db392e0d",
"md5": "1ae48ca3d5188bed7968a4ab47c31676",
"sha256": "e6e4db06431cdde4b2bb4817dcaaaa88180b63d35748255baa2839b14e126669"
},
"downloads": -1,
"filename": "timer_event-0.9.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1ae48ca3d5188bed7968a4ab47c31676",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 9969,
"upload_time": "2023-03-21T05:34:30",
"upload_time_iso_8601": "2023-03-21T05:34:30.961471Z",
"url": "https://files.pythonhosted.org/packages/17/de/020b2c2cf995fd9e4c29e5b4fc95eb962630f0b7053a903a8824db392e0d/timer_event-0.9.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3616c4746ab83746952f6fc2233c8a44fd016f0aab9877c4e2ee6e61dd766f2a",
"md5": "938966ed36b01a3d11427714b4dec5da",
"sha256": "8de4bf43a78c7f35ae3a897566df43ce19c0f49895085f363e8f39404e9d111d"
},
"downloads": -1,
"filename": "timer_event-0.9.1.tar.gz",
"has_sig": false,
"md5_digest": "938966ed36b01a3d11427714b4dec5da",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 9771,
"upload_time": "2023-03-21T05:34:36",
"upload_time_iso_8601": "2023-03-21T05:34:36.755095Z",
"url": "https://files.pythonhosted.org/packages/36/16/c4746ab83746952f6fc2233c8a44fd016f0aab9877c4e2ee6e61dd766f2a/timer_event-0.9.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-03-21 05:34:36",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "timer-event"
}