0

Say you wrote a function that returns the factorial of a number (factorial of 5 is 120 because 5*4*3*2*1=120) so if you have a huge number clearly it's going to take python a while to figure it out. Is it possible to have it run some while loop or something that runs while python figures out the factorial of x?

Darth Vador
  • 169
  • 2
  • 4
  • 12
  • Yes that is possible. It is called multithreading. [Here](https://stackoverflow.com/questions/2846653/how-to-use-threading-in-python) is a good explanation with some examples how to do it in python. – Flomp Aug 29 '17 at 07:25
  • @Flomp that's not a good idea: threads implementation in python are, lets say "not ideal". Read about GIL to see why. – Nir Alfasi Aug 29 '17 at 07:26
  • This is a broad question, I'm going to close it. – cs95 Aug 29 '17 at 07:27
  • @cᴏʟᴅsᴘᴇᴇᴅ I'd rather find something close enough to be a dup. That's not broad - the OP asks how to run code concurrently in python. A legit question. – Nir Alfasi Aug 29 '17 at 07:28
  • 1
    @alfasin Sorry... should've been clear - I was going to close this as a dupe :) – cs95 Aug 29 '17 at 07:30

1 Answers1

0

What you're looking for is to generate another process that will calculate factorial concurrently to the work that your current process is doing.

There's a module called subprocess that might interest you. Also see this.

Nir Alfasi
  • 53,191
  • 11
  • 86
  • 129