Python Forum
Multiprocessing: Threads work well. Processes don't work.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiprocessing: Threads work well. Processes don't work.
#8
Code :

from multiprocessing import Process
import os

def info(title):
    print(title)
    print('module name:', __name__)
    print('parent process:', os.getppid())
    print('process id:', os.getpid())

def f(name):
    info('function f')
    print('hello', name)

if __name__ == '__main__':    
    from time import time
    t0 = time()
    info('main line')
    p = Process(target=f, args=('bob',))
    p.start()
    p.join(1) #####
    print( 'main. end' )
    print( 'Time was :', time() - t0 )
Printout :

main line
module name: __main__
parent process: 4959
process id: 5722

and a dialog box :
Kill ?
Your program is still running!
Do you want to kill it?
'Ok' 'Cancelar'

Click 'Cancelar

main line
module name: __main__
parent process: 4959
process id: 5722
main. end
Time was : 91.7859697341919
Reply


Messages In This Thread
RE: Multiprocessing: Threads work well. Processes don't work. - by viyubu - Dec-03-2023, 07:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Seeking some script design advice... involves asyncio, threads, multiprocessing sawtooth500 0 94 Jun-27-2024, 05:56 PM
Last Post: sawtooth500
  equalto validator doesnt work robertkwild 1 248 Jun-02-2024, 06:16 AM
Last Post: Pedroski55
  I can't for the life of me get this basic If statement code to work CandleType1a 8 545 May-21-2024, 03:58 PM
Last Post: CandleType1a
  Extending list doesn't work as expected mmhmjanssen 2 381 May-09-2024, 05:39 PM
Last Post: Pedroski55
  Using xml.parsers.expat I can't get parser.ParseFile(f) to work Pedroski55 3 453 Apr-24-2024, 07:36 AM
Last Post: Pedroski55
  Making the tab key work like a tab key jackg 3 420 Apr-16-2024, 09:02 PM
Last Post: deanhystad
  print doesnt work in a function ony 2 471 Mar-11-2024, 12:42 PM
Last Post: Pedroski55
  Need some help trying to get my Python mortgage amortization calculator to work prope IamSirAskAlot 4 15,971 Feb-12-2024, 10:53 PM
Last Post: BerniceBerger
  Pydoc documentation doesnt work Cosmosso 5 4,655 Nov-25-2023, 11:17 PM
Last Post: vidito
  hi need help to make this code work correctly atulkul1985 5 1,040 Nov-20-2023, 04:38 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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