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?
#10
Then use subprocess:

(I have not tested the code)
import sys
import time
from subprocess import Popen


def start_script(filename):
    proc = Popen([sys.executeable, filename])
    return proc

# s3nd and r3ceive are bad names
sender_proc = start_script('s3nd.py')
receiver_proc = start_script('r3ceive.py')

# don't forget to put the if __name__ == '__main__'
# into your modules bottom and call the sender and receiver.

time.sleep(10)
sender_proc.terminate()
receiver_proc.terminate()
The question is, what happens if receiver runs before sender?
Your problems goes deeper as you think. The whole structure is wrong.

I think a Queue can solve this problems.
Writing to a file and reading it from another process is very fragile.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
RE: Multiprocessing doesn't seem to work? - by DeaD_EyE - Feb-13-2020, 05:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Extending list doesn't work as expected mmhmjanssen 2 231 May-09-2024, 05:39 PM
Last Post: Pedroski55
  Multiprocessing: Threads work well. Processes don't work. viyubu 11 1,968 Dec-03-2023, 08:50 PM
Last Post: snippsat
  Why doesn't calling a parent constructor work with arbitrary keyword arguments? PurposefulCoder 4 1,006 Jun-24-2023, 02:14 PM
Last Post: deanhystad
  Why doesn't this code work? What is wrong with path? Melcu54 7 1,923 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  color code doesn't work harryvl 1 948 Dec-29-2022, 08:59 PM
Last Post: deanhystad
  client.get_all_tickers() Doesn't work gerald 2 1,766 Jun-16-2022, 07:59 AM
Last Post: gerald
  pip doesn't work after Python upgrade Pavel_47 10 4,349 May-30-2022, 03:31 PM
Last Post: bowlofred
  For Loop Works Fine But Append For Pandas Doesn't Work knight2000 2 2,087 Dec-18-2021, 02:38 AM
Last Post: knight2000
  Class Method to Calculate Age Doesn't Work gdbengo 1 1,749 Oct-30-2021, 11:20 PM
Last Post: Yoriz
  Process doesn't work but Thread work ! mr_byte31 4 2,686 Oct-18-2021, 06:29 PM
Last Post: mr_byte31

Forum Jump:

User Panel Messages

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