Skip to content

Instantly share code, notes, and snippets.

@Williangalvani
Created February 25, 2015 21:12
Show Gist options
  • Save Williangalvani/599821f6541449206bfd to your computer and use it in GitHub Desktop.
Save Williangalvani/599821f6541449206bfd to your computer and use it in GitHub Desktop.
GNU nano 2.2.6 File: threads.py
import threading
import threadly
import time
def motor():
print "Motor", time.time()
def controle():
print "controle", time.time()
executor = threadly.Executor(2) #starts a thread pool with 2 threads
#these execute the task asap
#this will Execute a task in 100 ms
executor.schedule(controle, delay=100, recurring=True)
#this will Execute a task every second until removed
executor.schedule(motor, delay=10, recurring=True)
time.sleep(5)
#this shuts down the threadpool
executor.shutdown()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment