Skip to content

Python module that implements setInterval and setTimeout from Javascript.

License

Notifications You must be signed in to change notification settings

Shashwat986/jstimers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Javascript Timers in Python

This module allows Python users to use setTimeout() and setInterval() in their code.

I have not implemented setImmediate() because the only way to recreate functionality would be to have a clearImmediate() function that terminated a running thread. Killing a running thread is inherently unsafe, and, despite being possible, I don't think it's a good idea to implement it.

All timers are cleared at program exit.

Usage

import jstimers
from time import sleep

ctr = 0
def increment():
    global ctr
    ctr += 1

# Will increment ctr every 0.5 seconds.
intervalID = jstimers.setInterval(increment, 500)

def test(name):
    global ctr
    print ("Hello %s, %d" % (name,ctr))

# Will run after 2 seconds. Should have ctr = 3
timeoutID = jstimers.setTimeout(test, 2000, "World")

sleep(5)

About

Python module that implements setInterval and setTimeout from Javascript.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages