Thread safe message queue
Project description
threadmsg
Thread safe message queue
Table of contents
Install
$ pip3 install threadmsg
Examples
import threadmsg as tm
#--------------------------------------------------------------------
# Example 1
# Process messages
async def msgThread(ctx):
# Check for message
msg = ctx.getMsg()
if not msg:
return
print(msg)
# Create a thread
t1 = tm.ThreadMsg(msgThread)
# Send message to thread
t1.addMsg("Hello thread")
# Signal thread to quit and wait for thread to exit
t1.join()
#--------------------------------------------------------------------
# Example 2
async def myThread(ctx, v1, v2):
# Verify parameters
assert 5 == v1
assert 6 == v2
# Check if this is the first run
if not ctx.loops:
print('First call')
# Check if thread is exiting
if not ctx.run:
print('Thread is exiting')
# Return a negative number to exit thread
return -1
# Return a positive number and this function will be
# called again after that number of seconds
return 3.5
# Return zero this function will be called again immediately
return 0
# Return nothing for inifinite wait, this function will only
# be called again if a message is posted or quit is requested
return
# Create a thread, but don't start it
t1 = tm.ThreadMsg(myThread, (5, 6), False)
# Start thread
t1.start()
# Signal thread to quit
t1.stop()
# Wait for thread to exit
t1.join()
References
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for threadmsg-0.1.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02f689f42056e50c0ec47767fbcb21f01381a8659b7bd8e08b461a96c50d6c48 |
|
MD5 | ce075cdc9a7ce1f48de66357bed58212 |
|
BLAKE2b-256 | 6a4bd42b940a511e883ffb4aac604a19b1274a8e6610c37dd3928b96a81fe64b |