SkillAgentSearch skills...

PyThreads

A simple python library that makes creation of threads easier. It makes functions asynchronous with only one extra line of code.

Install / Use

/learn @Narasimha1997/PyThreads
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

PyThreads

A simple python library that makes creating and running threads easier. This library allows functions to behave asynchronously (similiar to JavaScript async functions).

Check the examples below:

Example 1:

Run two tasks in parallel:

from pythreads import pythread
from time import sleep

#create a pythread
@pythread
def task1():

    for i in range(10):

        print('Task1', i)
        sleep(2)


@pythread
def task2():

    for i in range(10):

        print('Task2', i)
        sleep(2)


#run the asynchronous functions
#task1 and task2 now behave like asynchronous functions
task1()
task2()

Example 2

Passing parameters

from pythreads import pythread
from time import sleep

@pythread
def task(times, sleep_time , name = "Prasanna"):

    for i in range(times):

        print(name)
        sleep(sleep_time)


def demo_call():
    task(10, 2)
    print("I execute first")

demo_call()
View on GitHub
GitHub Stars21
CategoryDevelopment
Updated5y ago
Forks1

Languages

Python

Security Score

75/100

Audited on Sep 21, 2020

No findings