Python Forum
Process doesn't work but Thread work !
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Process doesn't work but Thread work !
#1
I am just learning to work with multi threads/process.

I wrote this code and it works well:
import time
import concurrent.futures

numThreads = 3
def do_something(sec):
    print('start sleeping ',sec)
    time.sleep(sec)
    print('end sleeping ', sec)

sec = [5,4,3,2,1]

with concurrent.futures.ThreadPoolExecutor(max_workers = numThreads) as pool:
    pool.map(do_something, sec,timeout = 1)
when I switch from Thread to Process. Nothing is printed on the screen.
I think the code is not working at all.
import time
import concurrent.futures

numThreads = 3
def do_something(sec):
    print('start sleeping ',sec)
    time.sleep(sec)
    print('end sleeping ', sec)

sec = [5,4,3,2,1]

with concurrent.futures.ProcessPoolExecutor(max_workers = numThreads) as pool:
    pool.map(do_something, sec,timeout = 1)
any reason for this?
Reply


Messages In This Thread
Process doesn't work but Thread work ! - by mr_byte31 - Oct-18-2021, 05:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why does datetime.strptime() not work in this situation Monomial 2 1,123 Apr-08-2025, 06:36 PM
Last Post: snippsat
  PIP doesn't work YKR 1 843 Mar-28-2025, 02:10 PM
Last Post: snippsat
  Excel password recovery tool for work OTH 6 5,222 Mar-06-2025, 03:49 PM
Last Post: Pedroski55
  I'm trying to install python 3.11.11 on windows 10 - it doesn't work Petonique 2 2,685 Feb-04-2025, 05:42 PM
Last Post: snippsat
  Generators don't work svalencic 7 1,262 Jan-16-2025, 04:16 PM
Last Post: DeaD_EyE
  Trying to Make Steganography Program Work For All Payload Types Stegosaurus 0 1,369 Sep-26-2024, 12:43 PM
Last Post: Stegosaurus
  Can't get graph code to work properly. KDDDC2DS 1 758 Sep-16-2024, 09:17 PM
Last Post: deanhystad
  Questions about while loop - why does one work, and the other variant does not Swgeek 2 1,035 Aug-29-2024, 07:57 AM
Last Post: Swgeek
  How to make my Telegram bot stop working at 16:15 and not work on Fridays? hus73 2 1,587 Aug-10-2024, 12:06 PM
Last Post: hus73
  Executable file compiled by PyInstaller does not work on Windows 7 amusaber 1 2,238 Jul-11-2024, 02:59 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020