Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jczic/MicroWorkers
A micro workers class that easily manages a pool of threads to optimise simultaneous jobs and jobs endings, for MicroPython (used on Pycom modules & ESP32)
https://github.com/jczic/MicroWorkers
concurency concurrency esp32 hc2 jobs lopy micropython multithread multithreading pool pycom queue thread threads wipy worker-queue worker-threads workers
Last synced: about 1 month ago
JSON representation
A micro workers class that easily manages a pool of threads to optimise simultaneous jobs and jobs endings, for MicroPython (used on Pycom modules & ESP32)
- Host: GitHub
- URL: https://github.com/jczic/MicroWorkers
- Owner: jczic
- License: mit
- Created: 2018-03-06T22:18:12.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-09-19T22:43:45.000Z (about 5 years ago)
- Last Synced: 2024-10-27T23:17:55.084Z (about 2 months ago)
- Topics: concurency, concurrency, esp32, hc2, jobs, lopy, micropython, multithread, multithreading, pool, pycom, queue, thread, threads, wipy, worker-queue, worker-threads, workers
- Language: Python
- Homepage: https://microworkers.hc2.fr
- Size: 61.5 KB
- Stars: 41
- Watchers: 5
- Forks: 11
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-micropython-lib - MicroWorkers - A micro workers class that easily manages a pool of threads (Threading)
- awesome-micropython - MicroWorkers - A micro workers class that easily manages a pool of threads to optimise simultaneous jobs and jobs endings, for MicroPython (used on Pycom modules & ESP32). (Libraries / Threading)
README
### MicroWorkers is a class that easily manages a pool of threads to optimise simultaneous jobs and jobs endings, for MicroPython (used on ESP32 and [Pycom](http://www.pycom.io) modules)
![HC²](hc2.png "HC²")
Very easy to integrate and very light with one file only :
- `"microWorkers.py"`Simple but effective :
- Use it to create a multitasking jobs container
- Add jobs without blocking your main code
- Be alerted by an event when a job has finished### Using *microWorkers* class :
| Description | Function |
| - | - |
| Constructor | `workers = MicroWorkers(workersCount, workersStackSize=None)` |
| Adds a job | `workers.AddJob(name, function, arg=None, onFinished=None)` || Description | Property |
| - | - |
| Returns workers count | `workers.Count` |
| Returns emaining jobs count | `workers.JobsInQueue` |
| Returns jobs in process count | `workers.JobsInProcess` |
| Returns `True` if is in working | `workers.IsWorking` |### Simple example :
```python
from microWorkers import MicroWorkers
from time import sleepdef sleepJob(jobName, jobArg) :
sleep(10)
return Trueworkers = MicroWorkers(workersCount=5)
for i in range(5) :
workers.AddJob('Job %s' % i, sleepJob)
```### Example of using multiple jobs (with finished event) :
```python
from microWorkers import MicroWorkers
from time import sleepprint()
def jobA(jobName, jobArg) :
sleep(1)
return '%s:OK:1s' % jobNamedef jobB(jobName, jobArg) :
sleep(2)
return '%s:OK:2s' % jobNamedef jobC(jobName, jobArg) :
sleep(3)
return '%s:OK:3s' % jobNamedef jobFinished(jobName, jobArg, jobResult) :
print('Job %s finished (%s)' % (jobName, jobResult))# workersStackSize must be greater than zero
# it can be None to use the default stack size
workers = MicroWorkers(workersCount=5, workersStackSize=10*1024)for x in range(5) :
workers.AddJob('JobA.%s' % x, jobA, arg=None, onFinished=jobFinished)
workers.AddJob('JobB.%s' % x, jobB, arg=None, onFinished=jobFinished)
workers.AddJob('JobC.%s' % x, jobC, arg=None, onFinished=jobFinished)# Waiting end of all jobs,
while workers.IsWorking :
sleep(0.100)
```### By JC`zic for [HC²](https://www.hc2.fr) ;')
*Keep it simple, stupid* :+1: