L
L
leham12021-10-01 13:28:54
Python
leham1, 2021-10-01 13:28:54

Is it possible in python to make functions work at the same time?

Hello. How to make code run at the same time as other code. For example, in the code that I showed below, calls to the func_1 () function were simultaneously executed:

import time

def func_1(a):
    print(a)
    time.sleep(2)
    func_1(a)

func_1(1)
func_1(2)

# Результат должен быть таким:
1
2
1
2
1
2
1
2
и т.д.

I don't know for sure, but it's kind of called an asynchronous call.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dooMoob, 2021-10-01
@leham1

To find out exactly, you need to read:
https://docs.python.org/3/glossary.html#term-globa...
https://docs.python.org/3/library/multiprocessing.html
https:// docs.python.org/3/library/threading.html
https://docs.python.org/3/library/asyncio.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question