Python Forum
Using multiprocessing to produce objects for i in range
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using multiprocessing to produce objects for i in range
#3
(Feb-02-2022, 01:10 PM)deanhystad Wrote: This should work on linux, but it will not work on windows. In linux a process is forked, starting out with the same process image as the parent. In windows a process is spawned, starting out as a completely new process.

To have global variables in windows (and you should do this for linux too) you need to use the multiprocessor manager to create mutable objects that are shared among processes. When you spawn a process you pass the shared object as an argument.
import multiprocessing
...
manager = multiprocessing.Manager()
hotel = manager.list()
...
process = multiprocessing.Process(target=whatever, args=[hotel])
...

Thank you!

...wait, there are differences between linux and windows?

Well, I'll try it on my linux laptop. Thanks!

Would there be any way to do this on windows?
Reply


Messages In This Thread
RE: Using multiprocessing to produce objects for i in range - by lucasrohr - Feb-02-2022, 01:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Produce One file Per PurchaseOrder jland47 1 391 Jan-26-2024, 11:38 AM
Last Post: Larz60+
  matplotlib x axis range goes over the set range Pedroski55 5 3,328 Nov-21-2021, 08:40 AM
Last Post: paul18fr
Photo multiprocessing with objects? - help m3atwad 0 1,299 Nov-17-2020, 03:16 AM
Last Post: m3atwad
  Define a range, return all numbers of range that are NOT in csv data KiNeMs 18 7,271 Jan-24-2020, 06:19 AM
Last Post: KiNeMs
  Can the comments produce errors in python? newbieAuggie2019 9 4,439 Nov-26-2019, 12:19 AM
Last Post: micseydel
  Code works in IDLE, appears to work in CMD, but won't produce files in CMD/Windows ChrisPy33 3 3,301 Jun-12-2019, 05:56 AM
Last Post: ChrisPy33
  \t produce eight gap but tab only produce four gap liuzhiheng 3 2,436 Jun-09-2019, 07:05 PM
Last Post: Gribouillis
  Python Script to Produce Difference Between Files and Resolve DNS Query for the Outpu sultan 2 2,582 May-22-2019, 07:20 AM
Last Post: buran
  Convert file sizes: will this produce accurate results? RickyWilson 2 8,218 Dec-04-2017, 03:36 PM
Last Post: snippsat
  How can I produce a list of n times the same element? JoeB 6 3,825 Nov-27-2017, 10:40 PM
Last Post: wavic

Forum Jump:

User Panel Messages

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