Skip to content

Magic decorator syntax for asynchronous code in Python

License

Notifications You must be signed in to change notification settings

L3viathan/Threemorrow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Threemorrow

Magic decorator syntax for asynchronous code in Python 3.6

Please don't actually use this in production. It's more of a thought experiment

than anything else, and relies heavily on behavior specific to Python's old style classes. Pull requests, issues, comments and suggestions welcome.

Threemorrow is a spiritual fork of Tomorrow, which only worked in Python 2.7. I say spiritual, because it isn't an actual git fork, and the usage differs slightly (at least for the moment).

Usage

import time
import requests

from threemorrow import threads

urls = [
    'http://google.com',
    'http://facebook.com',
    'http://youtube.com',
    'http://baidu.com',
    'http://yahoo.com',
]

@threads(5)
def download(url):
    return requests.get(url)

if __name__ == '__main__':
    for url in urls:
        download(url)

    for result, args, kwargs in download:
        print(args[0], "resulted in", result)

About

Magic decorator syntax for asynchronous code in Python

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages