Skip to content

Commit

Permalink
Better fix for Python 2
Browse files Browse the repository at this point in the history
The multiprocessing module in Python 2 does not support
different contexts, so just fall back to the module
itself.
  • Loading branch information
benmwebb committed Jun 5, 2024
1 parent 06415df commit 6c1d0d6
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions modules/multifit/pyext/src/fit_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@


def _get_context():
# Use 'forkserver' rather than 'fork' start method if we can; 'fork' does
# not work well with multithreaded processes or CUDA
if (hasattr(multiprocessing, 'get_all_start_methods')
and 'forkserver' in multiprocessing.get_all_start_methods()):
return multiprocessing.get_context('forkserver')
if hasattr(multiprocessing, 'get_context'):
# Use 'forkserver' rather than 'fork' start method if we can;
# 'fork' does not work well with multithreaded processes or CUDA
if 'forkserver' in multiprocessing.get_all_start_methods():
return multiprocessing.get_context('forkserver')
else:
return multiprocessing.get_context()
else:
return multiprocessing.get_context()
# For Python < 3.4, just use the original module
return multiprocessing


class Fitter(object):
Expand Down

0 comments on commit 6c1d0d6

Please sign in to comment.