A
A
Alena2015-09-02 13:22:56
Python
Alena, 2015-09-02 13:22:56

How not to wait for a function call to finish in Python?

So I have a function like this:

import time

def f(a):
   if(a>1):
      time.sleep(3600)

f()
#код выполняется дальше

I gave such a function as an example of a function that takes a very long time. How to call a function and not wait for it to finish executing?
I would like to hear a short answer, and not a recommendation like "Read Lutz's three-volume book and you will understand everything"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bromzh, 2015-09-02
@Alien-Ka

https://docs.python.org/3/library/threading.html
Just keep in mind that python has a global lock, and such parallelization will be very conditional.
In general, it all depends on the task. If you are writing something network, then it is better to take tornado / asyncio or celery

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question