A synchronization primitive containing a value, allowing threads to concurrently set the value and peek the most recently set value.
Project description
messageboard
A synchronization primitive containing a value, allowing threads to concurrently set the value and peek the most recently set value.
Features
- Thread-safe.
.set(value)sets the value..peek()peeks the most recently set value. If no value is set yet,.peek()blocks until a value is set.
Usage
from __future__ import print_function
import random
random.seed(42)
import threading
import time
from messageboard import MessageBoard
def writer(message_board):
for i in range(10):
message_board.set(i)
print('Written', i)
time.sleep(1)
def reader(sticky_value):
for i in range(10):
if random.random() > 0.5:
sticky_value.peek()
print('Peeked', i)
time.sleep(1)
board = MessageBoard()
writer_thread = threading.Thread(target=writer, args=(board,))
writer_thread.daemon = True
reader_thread = threading.Thread(target=reader, args=(board,))
reader_thread.daemon = True
writer_thread.start()
reader_thread.start()
writer_thread.join()
reader_thread.join()
This produces the following output:
Written 0
Peeked 0
Written 1
Written 2
Written 3
Written 4
Peeked 4
Written 5
Peeked 5
Written 6
Peeked 6
Written 7
Written 8
Written 9
Contributing
Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file messageboard-0.1.0a0.tar.gz.
File metadata
- Download URL: messageboard-0.1.0a0.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aba86f283d86e7afab984f85a59eedb233820309f3ce08582244bca24021693a
|
|
| MD5 |
723165512ff1a830318a9708de365392
|
|
| BLAKE2b-256 |
a50cd712dbaa7b1b15752f7aa2f238cc3654cf5d02bc2f7ab468849f1b870979
|
File details
Details for the file messageboard-0.1.0a0-py2.py3-none-any.whl.
File metadata
- Download URL: messageboard-0.1.0a0-py2.py3-none-any.whl
- Upload date:
- Size: 3.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b259a7fcbde00f978e95c7446e49d07396ea5ef993aea868575e3fe11db7872
|
|
| MD5 |
495eaecf59704c9a90ef87fc3ce9bbac
|
|
| BLAKE2b-256 |
2c8c4d2a0f0ab71ce0bc15f96038b9f7571e409fded01e519644762e1d5c3732
|