Python Forum
Multiprocessing doesn't seem to work?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiprocessing doesn't seem to work?
#9
(Feb-13-2020, 02:16 PM)DeaD_EyE Wrote: In your modules, you call the function beginSending() and in the other beginRec().
Don't do this. Remove the call from both modules or use the boilerpate code:

Hey, thanks for pointing that out. I had the 'beginRec()' and 'beginSending()' calls at the bottom from when I was creating each module, and running the modules themselves 'as main' for testing... I guess I just never removed them... but I didn't think it would cause any harm. I will remove them and see what happens.

I created a simple, reproducible test to test out the multiprocessing implementation, and it works as expected:

main.py
from func1 import runMe
from func2 import runMeToo
import multiprocessing

def func1():
    runMe()

def func2():
    runMeToo()

if __name__ == "__main__":
    first = multiprocessing.Process(name='first', target=func1)
    second = multiprocessing.Process(name='second', target=func2)
    first.start()
    second.start()
func1
import time

def runMe():
    while True:
        print("function 1!")
        time.sleep(1)
        
func2
import time

def runMeToo():
   while True:
        print("function 2!")
        time.sleep(.5)
output:
Quote:> function 1!
> function 2!
> function 2!
> function 1!
... etc.

However, Ideally I would like a solution that simply kicks off both 'processes' in completely separate terminal shells. Each of my modules produce output that is important, but unrelated to the other module's function, so I would like to keep their outputs separated amongst two different terminal windows. How can I code something to simple kick off each module independently in seperate terminals?
Reply


Messages In This Thread
RE: Multiprocessing doesn't seem to work? - by t4keheart - Feb-13-2020, 04:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PIP doesn't work YKR 1 702 Mar-28-2025, 02:10 PM
Last Post: snippsat
  I'm trying to install python 3.11.11 on windows 10 - it doesn't work Petonique 2 1,944 Feb-04-2025, 05:42 PM
Last Post: snippsat
  Extending list doesn't work as expected mmhmjanssen 2 1,418 May-09-2024, 05:39 PM
Last Post: Pedroski55
  Multiprocessing: Threads work well. Processes don't work. viyubu 11 4,337 Dec-03-2023, 08:50 PM
Last Post: snippsat
  Why doesn't calling a parent constructor work with arbitrary keyword arguments? PurposefulCoder 4 1,946 Jun-24-2023, 02:14 PM
Last Post: deanhystad
  Why doesn't this code work? What is wrong with path? Melcu54 7 3,573 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  color code doesn't work harryvl 1 1,866 Dec-29-2022, 08:59 PM
Last Post: deanhystad
  client.get_all_tickers() Doesn't work gerald 2 2,624 Jun-16-2022, 07:59 AM
Last Post: gerald
  pip doesn't work after Python upgrade Pavel_47 10 6,846 May-30-2022, 03:31 PM
Last Post: bowlofred
  For Loop Works Fine But Append For Pandas Doesn't Work knight2000 2 3,051 Dec-18-2021, 02:38 AM
Last Post: knight2000

Forum Jump:

User Panel Messages

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