Package: pysimpleapp
pysimpleappSimple framework for applications in pythonAimsThis package is intended to provide the basic components for applications in Python.
It provides a white box implementation of multi threaded applications.pysimpleappwelcomes additional base classes and implementations of application methodologies.There is often more than one way to do something andpysimpleapptries to support
that by providing building blocks rather than solutions.It is intended to be GUI framework agnostic, although some common frameworks have been included for demonstration and ease of use.There should also be a relatively thorough set of tutorials alongside the main code.
This will teach how to use the software and explain why the software is this way.Source code:https://github.com/MagpieEmbedded/pysimpleappDocumentation:https://pysimpleapp.readthedocs.io.Free software: MIT licenseInstallationpysimpleappis hosted onPyPiso can be installed with:Simple ExamplesBelow are some simple examples which have been prepared.To understand how they work and how to build more complex applications, please visit thetutorialssection of the documentation.ThreadsOpen a python session withpysimpleappinstalled.Import libraries and classes:frompysimpleapp.messageimportMessagefrompysimpleapp.threads.examplesimportExampleSingleRunThread,ExampleMultiRunThreadfromqueueimportQueuefromthreadingimportThreadThreads take a name as the first argument, owner name as the second argument and an input and
output queue for communication.
Their use will be demonstrated shortly but you can confirm that they inherit from thethreading.Threadclass.Let’s create the input and output queues and an instance of the ExampleSingleRunThread class:in_queue=Queue()out_queue=Queue()single_run=ExampleSingleRunThread('Name','Owner',in_queue,out_queue)isinstance(single_run,Thread)# returns TrueNow, send the singe_run thread a start command.
Threads inpysimpleappoften have some built in commands, but it is very easy to override these and add your own later.It is also essential to define how you want a thread to behave through it’smainfunction.
The ExampleSingleRunThread has been defined to print that it has run.Put a start message in the input queue:# Note the order of owner and name because we are sending from the ownerin_queue.put(Message('Owner','Name','THREAD_START',None))This should print:Running single run thread...demonstrating that the thread has run!You will also notice that if you send another start command, nothing happens.
Single Run Threads execute once and then stop.Next, make an instance of ExampleMultiRunThread:multi_run=ExampleMultiRunThread('Name2','Owner',in_queue,out_queue)Multi Run Threads will run until they are told to end.
Test that functionality by providing several messages:in_queue.put(Message('Owner','Name2','THREAD_START',None))in_queue.put(Message('Owner','Name2','THREAD_START',None))in_queue.put(Message('Owner','Name2','THREAD_START',None))You will see that the thread has been counting how many times you asked it to run!End the thread with another built in command:in_queue.put(Message('Owner','Name2','THREAD_END',None))After this, the thread has stopped and will no longer respond to messages.This has been a very short introduction to some example threds but there is much more to come!
Continue learning with thetutorialsand soon you will be making your own threads for specific requirements.FeaturesTODOAttempt to implement best practicesDocumentation and tutorialsCreditsThis package was created withCookiecutterand theaudreyr/cookiecutter-pypackageproject template.History0.1.0 (2019-07-06)First release on PyPI.