Skip to content

Commit 36c3cd9

Browse files
authored
Merge pull request #5786 from chrisburr/fix-dirac_dms_directory_sync-macOS
[v7r2] Fix dirac-dms-directory-sync for macOS
2 parents 0d25721 + 2a7b0e8 commit 36c3cd9

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

src/DIRAC/DataManagementSystem/scripts/dirac_dms_directory_sync.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
from __future__ import print_function
3030

3131
import os
32-
from multiprocessing import Manager
32+
import multiprocessing
33+
34+
import six
3335

3436
import DIRAC
3537
from DIRAC import S_OK, S_ERROR, gConfig, gLogger
@@ -426,19 +428,25 @@ def runInParallel(arguments, listOfLists, function):
426428
"""
427429
Helper for execution of uploads and downloads in parallel
428430
"""
429-
from multiprocessing import Process
430-
431-
processes = []
432-
for tID, alist in enumerate(listOfLists):
433-
argums = arguments + [alist] + [tID]
434-
pro = Process(target=function, args=argums)
435-
pro.start()
436-
processes.append(pro)
437-
for process in processes:
438-
process.join()
439-
440-
if any(process.exitcode == 1 for process in processes):
441-
return S_ERROR()
431+
if len(listOfLists) == 1:
432+
function(*(arguments + listOfLists + [0]))
433+
else:
434+
if six.PY3 and multiprocessing.get_start_method() != "fork": # pylint: disable=no-member
435+
# This assumes that the "fork" strategy is used for new subprocesses
436+
# so they inherit DIRAC's global state. This is the default on Linux
437+
# however macOS and Windows use "spawn".
438+
raise NotImplementedError("Parallel uploading/downloading is only possible on Linux")
439+
processes = []
440+
for tID, alist in enumerate(listOfLists):
441+
argums = arguments + [alist] + [tID]
442+
pro = multiprocessing.Process(target=function, args=argums)
443+
pro.start()
444+
processes.append(pro)
445+
for process in processes:
446+
process.join()
447+
448+
if any(process.exitcode == 1 for process in processes):
449+
return S_ERROR()
442450
return S_OK()
443451

444452

@@ -521,7 +529,7 @@ def main():
521529
if switch[0].lower() == "j" or switch[0].lower() == "parallel":
522530
parallel = int(switch[1])
523531

524-
listOfFailedFiles = Manager().list()
532+
listOfFailedFiles = multiprocessing.Manager().list()
525533

526534
# This is the execution
527535
returnValue = run(args, sync, parallel)

0 commit comments

Comments
 (0)