Run two functions at different times

0 votes
I have two functions in a program. Function 1 should run for every 2 seconds. Function 2 should run for every 10 seconds. How can I implement this in python?
Jul 10, 2019 in Python by Shri
71 views

1 answer to this question.

0 votes

Please refer the below code for your problem:

import threading

def printit2():

  threading.Timer(2.0, printit2).start()

  print ("2")


def printit10():

  threading.Timer(10.0, printit10).start()

  print ("10")


printit2()

printit10()
answered Jul 10, 2019 by Rasheed

Related Questions In Python

0 votes
1 answer

how to run test cases of different modules with same marker at a time using pytest

Hey,@Nikitha, Suppose you have multiple files say test_sample1.py, test_sample2.py. To ...READ MORE

answered Apr 28, 2020 in Python by Gitika
• 65,850 points
80 views
0 votes
1 answer

Looping over two lists at once

You have to use the zip() function: for ...READ MORE

answered May 15, 2018 in Python by Nietzsche's daemon
• 4,260 points
1,003 views
0 votes
1 answer

How to print rows at different locations of pandas dataframe?

Like you are using row slicing, you ...READ MORE

answered May 12, 2019 in Python by Gani
487 views
0 votes
2 answers

How can I write a program to add two numbers using functions in python?

there is sum() function as a built ...READ MORE

answered Oct 24, 2020 in Python by anonymous
11,785 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,732 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points
1,323 views
0 votes
1 answer

Why am I getting a error when I am printing two different data types in python?

different data type is being used. that ...READ MORE

answered Mar 6, 2019 in Python by Mohammad
• 3,210 points
139 views
0 votes
1 answer