yet another confusion with multiprocessing error, 'module' object has no attribute 'f'










58















I know this has been answered before, but it seems that executing the script directly "python filename.py" does not work. I have Python 2.6.2 on SuSE Linux.



Code:



#!/usr/bin/python
# -*- coding: utf-8 -*-
from multiprocessing import Pool
p = Pool(1)
def f(x):
return x*x
p.map(f, [1, 2, 3])


Command line:



> python example.py
Process PoolWorker-1:
Traceback (most recent call last):
File "/usr/lib/python2.6/multiprocessing/process.py", line 231, in _bootstrap
self.run()
File "/usr/lib/python2.6/multiprocessing/process.py", line 88, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python2.6/multiprocessing/pool.py", line 57, in worker
task = get()
File "/usr/lib/python2.6/multiprocessing/queues.py", line 339, in get
return recv()
AttributeError: 'module' object has no attribute 'f'









share|improve this question

















  • 1





    possible duplicate of Using python multiprocessing Pool in the terminal and in code moudles for Django or Flask

    – jb.
    Aug 10 '14 at 13:00











  • @jb. that post is much later than this one, this was 2010, that one is 2013

    – gatoatigrado
    Aug 18 '14 at 23:26






  • 2





    Age is irrevelant there is consensus on meta that question with better answer should be chosen, and another one has IMO better answer.

    – jb.
    Aug 19 '14 at 7:52















58















I know this has been answered before, but it seems that executing the script directly "python filename.py" does not work. I have Python 2.6.2 on SuSE Linux.



Code:



#!/usr/bin/python
# -*- coding: utf-8 -*-
from multiprocessing import Pool
p = Pool(1)
def f(x):
return x*x
p.map(f, [1, 2, 3])


Command line:



> python example.py
Process PoolWorker-1:
Traceback (most recent call last):
File "/usr/lib/python2.6/multiprocessing/process.py", line 231, in _bootstrap
self.run()
File "/usr/lib/python2.6/multiprocessing/process.py", line 88, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python2.6/multiprocessing/pool.py", line 57, in worker
task = get()
File "/usr/lib/python2.6/multiprocessing/queues.py", line 339, in get
return recv()
AttributeError: 'module' object has no attribute 'f'









share|improve this question

















  • 1





    possible duplicate of Using python multiprocessing Pool in the terminal and in code moudles for Django or Flask

    – jb.
    Aug 10 '14 at 13:00











  • @jb. that post is much later than this one, this was 2010, that one is 2013

    – gatoatigrado
    Aug 18 '14 at 23:26






  • 2





    Age is irrevelant there is consensus on meta that question with better answer should be chosen, and another one has IMO better answer.

    – jb.
    Aug 19 '14 at 7:52













58












58








58


10






I know this has been answered before, but it seems that executing the script directly "python filename.py" does not work. I have Python 2.6.2 on SuSE Linux.



Code:



#!/usr/bin/python
# -*- coding: utf-8 -*-
from multiprocessing import Pool
p = Pool(1)
def f(x):
return x*x
p.map(f, [1, 2, 3])


Command line:



> python example.py
Process PoolWorker-1:
Traceback (most recent call last):
File "/usr/lib/python2.6/multiprocessing/process.py", line 231, in _bootstrap
self.run()
File "/usr/lib/python2.6/multiprocessing/process.py", line 88, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python2.6/multiprocessing/pool.py", line 57, in worker
task = get()
File "/usr/lib/python2.6/multiprocessing/queues.py", line 339, in get
return recv()
AttributeError: 'module' object has no attribute 'f'









share|improve this question














I know this has been answered before, but it seems that executing the script directly "python filename.py" does not work. I have Python 2.6.2 on SuSE Linux.



Code:



#!/usr/bin/python
# -*- coding: utf-8 -*-
from multiprocessing import Pool
p = Pool(1)
def f(x):
return x*x
p.map(f, [1, 2, 3])


Command line:



> python example.py
Process PoolWorker-1:
Traceback (most recent call last):
File "/usr/lib/python2.6/multiprocessing/process.py", line 231, in _bootstrap
self.run()
File "/usr/lib/python2.6/multiprocessing/process.py", line 88, in run
self._target(*self._args, **self._kwargs)
File "/usr/lib/python2.6/multiprocessing/pool.py", line 57, in worker
task = get()
File "/usr/lib/python2.6/multiprocessing/queues.py", line 339, in get
return recv()
AttributeError: 'module' object has no attribute 'f'






python multiprocessing






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked May 6 '10 at 17:08









gatoatigradogatoatigrado

8,688763127




8,688763127







  • 1





    possible duplicate of Using python multiprocessing Pool in the terminal and in code moudles for Django or Flask

    – jb.
    Aug 10 '14 at 13:00











  • @jb. that post is much later than this one, this was 2010, that one is 2013

    – gatoatigrado
    Aug 18 '14 at 23:26






  • 2





    Age is irrevelant there is consensus on meta that question with better answer should be chosen, and another one has IMO better answer.

    – jb.
    Aug 19 '14 at 7:52












  • 1





    possible duplicate of Using python multiprocessing Pool in the terminal and in code moudles for Django or Flask

    – jb.
    Aug 10 '14 at 13:00











  • @jb. that post is much later than this one, this was 2010, that one is 2013

    – gatoatigrado
    Aug 18 '14 at 23:26






  • 2





    Age is irrevelant there is consensus on meta that question with better answer should be chosen, and another one has IMO better answer.

    – jb.
    Aug 19 '14 at 7:52







1




1





possible duplicate of Using python multiprocessing Pool in the terminal and in code moudles for Django or Flask

– jb.
Aug 10 '14 at 13:00





possible duplicate of Using python multiprocessing Pool in the terminal and in code moudles for Django or Flask

– jb.
Aug 10 '14 at 13:00













@jb. that post is much later than this one, this was 2010, that one is 2013

– gatoatigrado
Aug 18 '14 at 23:26





@jb. that post is much later than this one, this was 2010, that one is 2013

– gatoatigrado
Aug 18 '14 at 23:26




2




2





Age is irrevelant there is consensus on meta that question with better answer should be chosen, and another one has IMO better answer.

– jb.
Aug 19 '14 at 7:52





Age is irrevelant there is consensus on meta that question with better answer should be chosen, and another one has IMO better answer.

– jb.
Aug 19 '14 at 7:52












5 Answers
5






active

oldest

votes


















114














Restructure your code so that the f() function is defined before you create instance of Pool. Otherwise the worker cannot see your function.



#!/usr/bin/python
# -*- coding: utf-8 -*-

from multiprocessing import Pool

def f(x):
return x*x

p = Pool(1)
p.map(f, [1, 2, 3])





share|improve this answer


















  • 7





    awesome, thank you so much!! What cryptic usage!

    – gatoatigrado
    May 7 '10 at 0:21







  • 1





    NOTE: A few years later, I've started writing an imap alternative [ github.com/gatoatigrado/vimap ], which makes this mistake more difficult (and makes it clear when threads are forked).

    – gatoatigrado
    Jun 13 '13 at 22:29






  • 1





    @Bartosz, Do you have any idea why this is not a problem in ipython notebooks?

    – Framester
    Oct 7 '14 at 9:33











  • @Framester: Odds are, ipython notebooks are using a "spawn" like approach to multiprocessing, rather than a "fork" based approach. The spawn based approach is to either launch a fresh process and import the main module (but not as __main__, to prevent it doing the if __name__ == '__main__:` stuff), or pickle interpreter state to transmit to child. fork semantics are faster, but only work on a single machine, and not on Windows. Spawn semantics can be made to work anywhere (e.g. Windows w/o fork), and can work on a cluster, and ipython notebooks are intended for multimachine cases.

    – ShadowRanger
    Apr 18 '16 at 17:16



















5














This one works:



#!/usr/bin/python
# -*- coding: utf-8 -*-
from multiprocessing import Pool

def f(x):
return x*x

if __name__ == "__main__":
p = Pool(1)
p.map(f, [1, 2, 3])


I'm not 100% sure why your code does not work, but I guess the reason is that child processes launched by the multiprocessing module try to import the main module (to have access to the methods you defined), and the if __name__ == "__main__" stanza is required not to execute the initialization code where you set up your pool.






share|improve this answer























  • If one has to run such code through an interpreter on Windows is there any work around? This is the situation I'm confronted with doing some Python-Fu programming from the Gimp Python Console plugin.

    – jxramos
    Mar 12 '15 at 2:40











  • This one did not work for me

    – Dang Manh Truong
    Nov 4 '17 at 11:07












  • @Tamás, it does not work for me either, from multiprocessing import Pool, ImportError: cannot import name Pool

    – Houy Narun
    May 29 '18 at 6:31


















1














One possibility is that your python file has the same name as a module:



  • test.py

  • test/
    • __init__.py


in pickle.py, you have the error coming from:



 def find_class(self, module, name):
# Subclasses may override this
__import__(module)
mod = sys.modules[module] # <- here mod will reference your test/__init__.py
klass = getattr(mod, name)
return klass





share|improve this answer






























    0














    The problem I had was solved by using if __name__ == "__main__" as pointed out by Tamás; in Eclipse for Windows the examples do not work under the interpreter.
    This is explained in
    http://docs.python.org/2/library/multiprocessing






    share|improve this answer






























      0














      This comes from the fact that with p = Pool(1) the main process forks processes (threads vs processes) before it creates the function f. As stated in Bartosz answer the spawned processes do not have access to the new function.



      def f1(x):
      ...

      p = Pool(1) # p is spawned and is now an independent process, knows f1

      def f(x): # p doesn't not share this object
      ...





      share|improve this answer






















        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/3.0/"u003ecc by-sa 3.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%2f2782961%2fyet-another-confusion-with-multiprocessing-error-module-object-has-no-attribu%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        5 Answers
        5






        active

        oldest

        votes








        5 Answers
        5






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        114














        Restructure your code so that the f() function is defined before you create instance of Pool. Otherwise the worker cannot see your function.



        #!/usr/bin/python
        # -*- coding: utf-8 -*-

        from multiprocessing import Pool

        def f(x):
        return x*x

        p = Pool(1)
        p.map(f, [1, 2, 3])





        share|improve this answer


















        • 7





          awesome, thank you so much!! What cryptic usage!

          – gatoatigrado
          May 7 '10 at 0:21







        • 1





          NOTE: A few years later, I've started writing an imap alternative [ github.com/gatoatigrado/vimap ], which makes this mistake more difficult (and makes it clear when threads are forked).

          – gatoatigrado
          Jun 13 '13 at 22:29






        • 1





          @Bartosz, Do you have any idea why this is not a problem in ipython notebooks?

          – Framester
          Oct 7 '14 at 9:33











        • @Framester: Odds are, ipython notebooks are using a "spawn" like approach to multiprocessing, rather than a "fork" based approach. The spawn based approach is to either launch a fresh process and import the main module (but not as __main__, to prevent it doing the if __name__ == '__main__:` stuff), or pickle interpreter state to transmit to child. fork semantics are faster, but only work on a single machine, and not on Windows. Spawn semantics can be made to work anywhere (e.g. Windows w/o fork), and can work on a cluster, and ipython notebooks are intended for multimachine cases.

          – ShadowRanger
          Apr 18 '16 at 17:16
















        114














        Restructure your code so that the f() function is defined before you create instance of Pool. Otherwise the worker cannot see your function.



        #!/usr/bin/python
        # -*- coding: utf-8 -*-

        from multiprocessing import Pool

        def f(x):
        return x*x

        p = Pool(1)
        p.map(f, [1, 2, 3])





        share|improve this answer


















        • 7





          awesome, thank you so much!! What cryptic usage!

          – gatoatigrado
          May 7 '10 at 0:21







        • 1





          NOTE: A few years later, I've started writing an imap alternative [ github.com/gatoatigrado/vimap ], which makes this mistake more difficult (and makes it clear when threads are forked).

          – gatoatigrado
          Jun 13 '13 at 22:29






        • 1





          @Bartosz, Do you have any idea why this is not a problem in ipython notebooks?

          – Framester
          Oct 7 '14 at 9:33











        • @Framester: Odds are, ipython notebooks are using a "spawn" like approach to multiprocessing, rather than a "fork" based approach. The spawn based approach is to either launch a fresh process and import the main module (but not as __main__, to prevent it doing the if __name__ == '__main__:` stuff), or pickle interpreter state to transmit to child. fork semantics are faster, but only work on a single machine, and not on Windows. Spawn semantics can be made to work anywhere (e.g. Windows w/o fork), and can work on a cluster, and ipython notebooks are intended for multimachine cases.

          – ShadowRanger
          Apr 18 '16 at 17:16














        114












        114








        114







        Restructure your code so that the f() function is defined before you create instance of Pool. Otherwise the worker cannot see your function.



        #!/usr/bin/python
        # -*- coding: utf-8 -*-

        from multiprocessing import Pool

        def f(x):
        return x*x

        p = Pool(1)
        p.map(f, [1, 2, 3])





        share|improve this answer













        Restructure your code so that the f() function is defined before you create instance of Pool. Otherwise the worker cannot see your function.



        #!/usr/bin/python
        # -*- coding: utf-8 -*-

        from multiprocessing import Pool

        def f(x):
        return x*x

        p = Pool(1)
        p.map(f, [1, 2, 3])






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 6 '10 at 17:15









        BartoszBartosz

        4,69522115




        4,69522115







        • 7





          awesome, thank you so much!! What cryptic usage!

          – gatoatigrado
          May 7 '10 at 0:21







        • 1





          NOTE: A few years later, I've started writing an imap alternative [ github.com/gatoatigrado/vimap ], which makes this mistake more difficult (and makes it clear when threads are forked).

          – gatoatigrado
          Jun 13 '13 at 22:29






        • 1





          @Bartosz, Do you have any idea why this is not a problem in ipython notebooks?

          – Framester
          Oct 7 '14 at 9:33











        • @Framester: Odds are, ipython notebooks are using a "spawn" like approach to multiprocessing, rather than a "fork" based approach. The spawn based approach is to either launch a fresh process and import the main module (but not as __main__, to prevent it doing the if __name__ == '__main__:` stuff), or pickle interpreter state to transmit to child. fork semantics are faster, but only work on a single machine, and not on Windows. Spawn semantics can be made to work anywhere (e.g. Windows w/o fork), and can work on a cluster, and ipython notebooks are intended for multimachine cases.

          – ShadowRanger
          Apr 18 '16 at 17:16













        • 7





          awesome, thank you so much!! What cryptic usage!

          – gatoatigrado
          May 7 '10 at 0:21







        • 1





          NOTE: A few years later, I've started writing an imap alternative [ github.com/gatoatigrado/vimap ], which makes this mistake more difficult (and makes it clear when threads are forked).

          – gatoatigrado
          Jun 13 '13 at 22:29






        • 1





          @Bartosz, Do you have any idea why this is not a problem in ipython notebooks?

          – Framester
          Oct 7 '14 at 9:33











        • @Framester: Odds are, ipython notebooks are using a "spawn" like approach to multiprocessing, rather than a "fork" based approach. The spawn based approach is to either launch a fresh process and import the main module (but not as __main__, to prevent it doing the if __name__ == '__main__:` stuff), or pickle interpreter state to transmit to child. fork semantics are faster, but only work on a single machine, and not on Windows. Spawn semantics can be made to work anywhere (e.g. Windows w/o fork), and can work on a cluster, and ipython notebooks are intended for multimachine cases.

          – ShadowRanger
          Apr 18 '16 at 17:16








        7




        7





        awesome, thank you so much!! What cryptic usage!

        – gatoatigrado
        May 7 '10 at 0:21






        awesome, thank you so much!! What cryptic usage!

        – gatoatigrado
        May 7 '10 at 0:21





        1




        1





        NOTE: A few years later, I've started writing an imap alternative [ github.com/gatoatigrado/vimap ], which makes this mistake more difficult (and makes it clear when threads are forked).

        – gatoatigrado
        Jun 13 '13 at 22:29





        NOTE: A few years later, I've started writing an imap alternative [ github.com/gatoatigrado/vimap ], which makes this mistake more difficult (and makes it clear when threads are forked).

        – gatoatigrado
        Jun 13 '13 at 22:29




        1




        1





        @Bartosz, Do you have any idea why this is not a problem in ipython notebooks?

        – Framester
        Oct 7 '14 at 9:33





        @Bartosz, Do you have any idea why this is not a problem in ipython notebooks?

        – Framester
        Oct 7 '14 at 9:33













        @Framester: Odds are, ipython notebooks are using a "spawn" like approach to multiprocessing, rather than a "fork" based approach. The spawn based approach is to either launch a fresh process and import the main module (but not as __main__, to prevent it doing the if __name__ == '__main__:` stuff), or pickle interpreter state to transmit to child. fork semantics are faster, but only work on a single machine, and not on Windows. Spawn semantics can be made to work anywhere (e.g. Windows w/o fork), and can work on a cluster, and ipython notebooks are intended for multimachine cases.

        – ShadowRanger
        Apr 18 '16 at 17:16






        @Framester: Odds are, ipython notebooks are using a "spawn" like approach to multiprocessing, rather than a "fork" based approach. The spawn based approach is to either launch a fresh process and import the main module (but not as __main__, to prevent it doing the if __name__ == '__main__:` stuff), or pickle interpreter state to transmit to child. fork semantics are faster, but only work on a single machine, and not on Windows. Spawn semantics can be made to work anywhere (e.g. Windows w/o fork), and can work on a cluster, and ipython notebooks are intended for multimachine cases.

        – ShadowRanger
        Apr 18 '16 at 17:16














        5














        This one works:



        #!/usr/bin/python
        # -*- coding: utf-8 -*-
        from multiprocessing import Pool

        def f(x):
        return x*x

        if __name__ == "__main__":
        p = Pool(1)
        p.map(f, [1, 2, 3])


        I'm not 100% sure why your code does not work, but I guess the reason is that child processes launched by the multiprocessing module try to import the main module (to have access to the methods you defined), and the if __name__ == "__main__" stanza is required not to execute the initialization code where you set up your pool.






        share|improve this answer























        • If one has to run such code through an interpreter on Windows is there any work around? This is the situation I'm confronted with doing some Python-Fu programming from the Gimp Python Console plugin.

          – jxramos
          Mar 12 '15 at 2:40











        • This one did not work for me

          – Dang Manh Truong
          Nov 4 '17 at 11:07












        • @Tamás, it does not work for me either, from multiprocessing import Pool, ImportError: cannot import name Pool

          – Houy Narun
          May 29 '18 at 6:31















        5














        This one works:



        #!/usr/bin/python
        # -*- coding: utf-8 -*-
        from multiprocessing import Pool

        def f(x):
        return x*x

        if __name__ == "__main__":
        p = Pool(1)
        p.map(f, [1, 2, 3])


        I'm not 100% sure why your code does not work, but I guess the reason is that child processes launched by the multiprocessing module try to import the main module (to have access to the methods you defined), and the if __name__ == "__main__" stanza is required not to execute the initialization code where you set up your pool.






        share|improve this answer























        • If one has to run such code through an interpreter on Windows is there any work around? This is the situation I'm confronted with doing some Python-Fu programming from the Gimp Python Console plugin.

          – jxramos
          Mar 12 '15 at 2:40











        • This one did not work for me

          – Dang Manh Truong
          Nov 4 '17 at 11:07












        • @Tamás, it does not work for me either, from multiprocessing import Pool, ImportError: cannot import name Pool

          – Houy Narun
          May 29 '18 at 6:31













        5












        5








        5







        This one works:



        #!/usr/bin/python
        # -*- coding: utf-8 -*-
        from multiprocessing import Pool

        def f(x):
        return x*x

        if __name__ == "__main__":
        p = Pool(1)
        p.map(f, [1, 2, 3])


        I'm not 100% sure why your code does not work, but I guess the reason is that child processes launched by the multiprocessing module try to import the main module (to have access to the methods you defined), and the if __name__ == "__main__" stanza is required not to execute the initialization code where you set up your pool.






        share|improve this answer













        This one works:



        #!/usr/bin/python
        # -*- coding: utf-8 -*-
        from multiprocessing import Pool

        def f(x):
        return x*x

        if __name__ == "__main__":
        p = Pool(1)
        p.map(f, [1, 2, 3])


        I'm not 100% sure why your code does not work, but I guess the reason is that child processes launched by the multiprocessing module try to import the main module (to have access to the methods you defined), and the if __name__ == "__main__" stanza is required not to execute the initialization code where you set up your pool.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 6 '10 at 17:15









        TamásTamás

        37.9k882109




        37.9k882109












        • If one has to run such code through an interpreter on Windows is there any work around? This is the situation I'm confronted with doing some Python-Fu programming from the Gimp Python Console plugin.

          – jxramos
          Mar 12 '15 at 2:40











        • This one did not work for me

          – Dang Manh Truong
          Nov 4 '17 at 11:07












        • @Tamás, it does not work for me either, from multiprocessing import Pool, ImportError: cannot import name Pool

          – Houy Narun
          May 29 '18 at 6:31

















        • If one has to run such code through an interpreter on Windows is there any work around? This is the situation I'm confronted with doing some Python-Fu programming from the Gimp Python Console plugin.

          – jxramos
          Mar 12 '15 at 2:40











        • This one did not work for me

          – Dang Manh Truong
          Nov 4 '17 at 11:07












        • @Tamás, it does not work for me either, from multiprocessing import Pool, ImportError: cannot import name Pool

          – Houy Narun
          May 29 '18 at 6:31
















        If one has to run such code through an interpreter on Windows is there any work around? This is the situation I'm confronted with doing some Python-Fu programming from the Gimp Python Console plugin.

        – jxramos
        Mar 12 '15 at 2:40





        If one has to run such code through an interpreter on Windows is there any work around? This is the situation I'm confronted with doing some Python-Fu programming from the Gimp Python Console plugin.

        – jxramos
        Mar 12 '15 at 2:40













        This one did not work for me

        – Dang Manh Truong
        Nov 4 '17 at 11:07






        This one did not work for me

        – Dang Manh Truong
        Nov 4 '17 at 11:07














        @Tamás, it does not work for me either, from multiprocessing import Pool, ImportError: cannot import name Pool

        – Houy Narun
        May 29 '18 at 6:31





        @Tamás, it does not work for me either, from multiprocessing import Pool, ImportError: cannot import name Pool

        – Houy Narun
        May 29 '18 at 6:31











        1














        One possibility is that your python file has the same name as a module:



        • test.py

        • test/
          • __init__.py


        in pickle.py, you have the error coming from:



         def find_class(self, module, name):
        # Subclasses may override this
        __import__(module)
        mod = sys.modules[module] # <- here mod will reference your test/__init__.py
        klass = getattr(mod, name)
        return klass





        share|improve this answer



























          1














          One possibility is that your python file has the same name as a module:



          • test.py

          • test/
            • __init__.py


          in pickle.py, you have the error coming from:



           def find_class(self, module, name):
          # Subclasses may override this
          __import__(module)
          mod = sys.modules[module] # <- here mod will reference your test/__init__.py
          klass = getattr(mod, name)
          return klass





          share|improve this answer

























            1












            1








            1







            One possibility is that your python file has the same name as a module:



            • test.py

            • test/
              • __init__.py


            in pickle.py, you have the error coming from:



             def find_class(self, module, name):
            # Subclasses may override this
            __import__(module)
            mod = sys.modules[module] # <- here mod will reference your test/__init__.py
            klass = getattr(mod, name)
            return klass





            share|improve this answer













            One possibility is that your python file has the same name as a module:



            • test.py

            • test/
              • __init__.py


            in pickle.py, you have the error coming from:



             def find_class(self, module, name):
            # Subclasses may override this
            __import__(module)
            mod = sys.modules[module] # <- here mod will reference your test/__init__.py
            klass = getattr(mod, name)
            return klass






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Oct 13 '12 at 6:42









            user1143523user1143523

            443




            443





















                0














                The problem I had was solved by using if __name__ == "__main__" as pointed out by Tamás; in Eclipse for Windows the examples do not work under the interpreter.
                This is explained in
                http://docs.python.org/2/library/multiprocessing






                share|improve this answer



























                  0














                  The problem I had was solved by using if __name__ == "__main__" as pointed out by Tamás; in Eclipse for Windows the examples do not work under the interpreter.
                  This is explained in
                  http://docs.python.org/2/library/multiprocessing






                  share|improve this answer

























                    0












                    0








                    0







                    The problem I had was solved by using if __name__ == "__main__" as pointed out by Tamás; in Eclipse for Windows the examples do not work under the interpreter.
                    This is explained in
                    http://docs.python.org/2/library/multiprocessing






                    share|improve this answer













                    The problem I had was solved by using if __name__ == "__main__" as pointed out by Tamás; in Eclipse for Windows the examples do not work under the interpreter.
                    This is explained in
                    http://docs.python.org/2/library/multiprocessing







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 30 '13 at 11:09









                    user2226924user2226924

                    16625




                    16625





















                        0














                        This comes from the fact that with p = Pool(1) the main process forks processes (threads vs processes) before it creates the function f. As stated in Bartosz answer the spawned processes do not have access to the new function.



                        def f1(x):
                        ...

                        p = Pool(1) # p is spawned and is now an independent process, knows f1

                        def f(x): # p doesn't not share this object
                        ...





                        share|improve this answer



























                          0














                          This comes from the fact that with p = Pool(1) the main process forks processes (threads vs processes) before it creates the function f. As stated in Bartosz answer the spawned processes do not have access to the new function.



                          def f1(x):
                          ...

                          p = Pool(1) # p is spawned and is now an independent process, knows f1

                          def f(x): # p doesn't not share this object
                          ...





                          share|improve this answer

























                            0












                            0








                            0







                            This comes from the fact that with p = Pool(1) the main process forks processes (threads vs processes) before it creates the function f. As stated in Bartosz answer the spawned processes do not have access to the new function.



                            def f1(x):
                            ...

                            p = Pool(1) # p is spawned and is now an independent process, knows f1

                            def f(x): # p doesn't not share this object
                            ...





                            share|improve this answer













                            This comes from the fact that with p = Pool(1) the main process forks processes (threads vs processes) before it creates the function f. As stated in Bartosz answer the spawned processes do not have access to the new function.



                            def f1(x):
                            ...

                            p = Pool(1) # p is spawned and is now an independent process, knows f1

                            def f(x): # p doesn't not share this object
                            ...






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 14 '18 at 1:24









                            yosemite_kyosemite_k

                            890420




                            890420



























                                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%2f2782961%2fyet-another-confusion-with-multiprocessing-error-module-object-has-no-attribu%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







                                這個網誌中的熱門文章

                                How to read a connectionString WITH PROVIDER in .NET Core?

                                In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

                                Museum of Modern and Contemporary Art of Trento and Rovereto