How to call multiprocessing code in Python instance method without deadlockingPython multiprocessing: object identifier unique across processesPython multiprocessing queues slower than pool.mapMultiprocess tasks in python that can't be pickled?Multiprocess in python uses only one processHow to maintain class state when executing class methods for multiple classes in parallel?Calling a normal function after multiprocessingpython multiprocessing .join() deadlock depends on worker functionPython Multiprocessing Pool Worker Processes Failing to TerminatePython multiprocessing and too many open filesPython Multiprocessing Not Speeding Up

Closed Loop System

Two people from small group of friends want to have a "meeting" with me. The circumstances are strange and give me a bad feeling

Did Ohio pass a law granting students the right to give scientifically wrong answers consistent with their religious beliefs?

How can I find out where to buy uncommon (for the location) items while traveling?

Can a verb be modified too many times?

"Indexed" version of compactness and Axiom of Choice

Locked folder with obscure app from Sourceforge, now cannot unlock folder

SSD not reaching advertised speed

Hot Rim Looking for Suggestions

Prevent function taking const std::string& from accepting 0

SSH host identification changes on one wireless network

Are conjugate vectors unique?

Beyond breadboards? Good ways to package simple GPIO-using project?

Hand propping Cessna 172N, with a pilot and a non intuned passenger

Is there a preferred time in their presidency when US presidents pardon the most people?

What is :>filename.txt Doing?

How to handle a colleague who appears helpful in front of manager but doesn't help in private?

What does "parallel in-register" mean for a protein structure in a fibril?

Is Earth's Surface "In orbit"?

N-Dimensional Cartesian Product

Ethics: Is it ethical for a professor to conduct research using a student's ideas without giving them credit?

Why does this process map every fraction to the golden ratio?

What's the best way for guitar and piano to play together in a jazz quartet?

How do you get the Super Rod in Pokémon Sword and Shield?



How to call multiprocessing code in Python instance method without deadlocking


Python multiprocessing: object identifier unique across processesPython multiprocessing queues slower than pool.mapMultiprocess tasks in python that can't be pickled?Multiprocess in python uses only one processHow to maintain class state when executing class methods for multiple classes in parallel?Calling a normal function after multiprocessingpython multiprocessing .join() deadlock depends on worker functionPython Multiprocessing Pool Worker Processes Failing to TerminatePython multiprocessing and too many open filesPython Multiprocessing Not Speeding Up






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









0


















I want to use the multiprocessing library in Python to parallelize reading files and storing loaded information to a list. I also want this method for loading files in parallel to be an instance method that can also be called by other instance methods for some class.



When I call the parallelized loading function (ie. load_multiple_files) the first time, the data is loaded in parallel and returned as expected. However, the second time the function is called, the processes deadlock.



I tried reordering the two calls (i.e. results_B before results_A), and the processes deadlock on the second call. I also tried removing pool.join(), but that was unsuccessful.



Here is some current pseudocode:



class Foo():
def __init__(self, filepaths_A: List[str], filepaths_B: List[str]):
results_A = load_multiple_files(filepaths_A) # works as expected, with files loaded in parallel
results_B = load_multiple_files(filepaths_B) # processes deadlock and program hangs

def load_file(self, filepath: str):
# load file and return a numpy array
with File(filepath, 'r') as f:
result = l['data'][:]
return result

def load_multiple_files(self, filepaths: List[str]):
""" Wrapper for loading multiple files in parallel
pool = mp.Pool()
results = pool.map(self.load_file, filepaths)
pool.close()
pool.join()

return results


I expect that regardless of the number of times the load_multiple_files method is called, the loading process will be parallelized and will return the loaded data.



Any potential solutions to this problem using multiprocessing.Pool?










share|improve this question































    0


















    I want to use the multiprocessing library in Python to parallelize reading files and storing loaded information to a list. I also want this method for loading files in parallel to be an instance method that can also be called by other instance methods for some class.



    When I call the parallelized loading function (ie. load_multiple_files) the first time, the data is loaded in parallel and returned as expected. However, the second time the function is called, the processes deadlock.



    I tried reordering the two calls (i.e. results_B before results_A), and the processes deadlock on the second call. I also tried removing pool.join(), but that was unsuccessful.



    Here is some current pseudocode:



    class Foo():
    def __init__(self, filepaths_A: List[str], filepaths_B: List[str]):
    results_A = load_multiple_files(filepaths_A) # works as expected, with files loaded in parallel
    results_B = load_multiple_files(filepaths_B) # processes deadlock and program hangs

    def load_file(self, filepath: str):
    # load file and return a numpy array
    with File(filepath, 'r') as f:
    result = l['data'][:]
    return result

    def load_multiple_files(self, filepaths: List[str]):
    """ Wrapper for loading multiple files in parallel
    pool = mp.Pool()
    results = pool.map(self.load_file, filepaths)
    pool.close()
    pool.join()

    return results


    I expect that regardless of the number of times the load_multiple_files method is called, the loading process will be parallelized and will return the loaded data.



    Any potential solutions to this problem using multiprocessing.Pool?










    share|improve this question



























      0













      0









      0


      0






      I want to use the multiprocessing library in Python to parallelize reading files and storing loaded information to a list. I also want this method for loading files in parallel to be an instance method that can also be called by other instance methods for some class.



      When I call the parallelized loading function (ie. load_multiple_files) the first time, the data is loaded in parallel and returned as expected. However, the second time the function is called, the processes deadlock.



      I tried reordering the two calls (i.e. results_B before results_A), and the processes deadlock on the second call. I also tried removing pool.join(), but that was unsuccessful.



      Here is some current pseudocode:



      class Foo():
      def __init__(self, filepaths_A: List[str], filepaths_B: List[str]):
      results_A = load_multiple_files(filepaths_A) # works as expected, with files loaded in parallel
      results_B = load_multiple_files(filepaths_B) # processes deadlock and program hangs

      def load_file(self, filepath: str):
      # load file and return a numpy array
      with File(filepath, 'r') as f:
      result = l['data'][:]
      return result

      def load_multiple_files(self, filepaths: List[str]):
      """ Wrapper for loading multiple files in parallel
      pool = mp.Pool()
      results = pool.map(self.load_file, filepaths)
      pool.close()
      pool.join()

      return results


      I expect that regardless of the number of times the load_multiple_files method is called, the loading process will be parallelized and will return the loaded data.



      Any potential solutions to this problem using multiprocessing.Pool?










      share|improve this question














      I want to use the multiprocessing library in Python to parallelize reading files and storing loaded information to a list. I also want this method for loading files in parallel to be an instance method that can also be called by other instance methods for some class.



      When I call the parallelized loading function (ie. load_multiple_files) the first time, the data is loaded in parallel and returned as expected. However, the second time the function is called, the processes deadlock.



      I tried reordering the two calls (i.e. results_B before results_A), and the processes deadlock on the second call. I also tried removing pool.join(), but that was unsuccessful.



      Here is some current pseudocode:



      class Foo():
      def __init__(self, filepaths_A: List[str], filepaths_B: List[str]):
      results_A = load_multiple_files(filepaths_A) # works as expected, with files loaded in parallel
      results_B = load_multiple_files(filepaths_B) # processes deadlock and program hangs

      def load_file(self, filepath: str):
      # load file and return a numpy array
      with File(filepath, 'r') as f:
      result = l['data'][:]
      return result

      def load_multiple_files(self, filepaths: List[str]):
      """ Wrapper for loading multiple files in parallel
      pool = mp.Pool()
      results = pool.map(self.load_file, filepaths)
      pool.close()
      pool.join()

      return results


      I expect that regardless of the number of times the load_multiple_files method is called, the loading process will be parallelized and will return the loaded data.



      Any potential solutions to this problem using multiprocessing.Pool?







      python-multiprocessing






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 28 at 22:08









      aadaad

      386 bronze badges




      386 bronze badges

























          0






          active

          oldest

          votes













          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );














          draft saved

          draft discarded
















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55407596%2fhow-to-call-multiprocessing-code-in-python-instance-method-without-deadlocking%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown


























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55407596%2fhow-to-call-multiprocessing-code-in-python-instance-method-without-deadlocking%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown









          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현