Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiprocessing hangs in iPython console #1900

Open
spyder-bot opened this issue Feb 17, 2015 · 21 comments
Open

Multiprocessing hangs in iPython console #1900

spyder-bot opened this issue Feb 17, 2015 · 21 comments

Comments

@spyder-bot
Copy link
Collaborator

From oscarbra...@gmail.com on 2014-07-20T01:09:49Z

Spyder Version: 2.3.0
Python Version: 2.7.8
Qt Version : 4.8.6, PyQt4 (API v2) 4.10.4 on Darwin
pyflakes >=0.5.0: None (NOK)
pep8 >=0.6 : None (NOK)
IPython >=0.13 : 2.1.0 (OK)
pygments >=1.6 : 1.6 (OK)
sphinx >=0.6.6 : None (NOK)
psutil >=0.3 : None (NOK)
rope >=0.9.2 : None (NOK)
matplotlib >=1.0: 1.3.1 (OK)
sympy >=0.7.0 : 0.7.5 (OK)
pylint >=0.25 : None (NOK)

What steps will reproduce the problem?

  1. Run the following:

from multiprocessing import Pool

eg = [1,2,3,4,5,6,7]

def multi_fn(x):
return x**2

pool = Pool()
out = pool.map(multi_fn,eg)
pool.close()
pool.join()

In the normal python console, this will complete with no problems.

In the ipython console, this will hand on 'pool.join()'

The code works in iPython notebook, iPython run in terminal and normal python run in terminal.

The hang appears to be unique to the ipython console within Spyder - any ideas what is causing this?

Original issue: http://code.google.com/p/spyderlib/issues/detail?id=1900

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2014-08-17T10:19:05Z

Labels: Cat-IPythonConsole MS-v2.3.2

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2014-09-20T14:58:18Z

This is working fine for me on Linux. Could you check if this is still an issue with 2.3.1?

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2014-09-21T10:51:30Z

We need to verify if this is a problem in Mac and/or Windows, before closing the issue.

Labels: Easy

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2014-10-31T15:07:53Z

Labels: -MS-v2.3.2 MS-v2.3.3

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2015-01-08T15:10:53Z

Labels: -MS-v2.3.3 MS-v2.3.4

@ccordoba12 ccordoba12 modified the milestones: v2.4, v2.3.4 Mar 7, 2015
@mikofski
Copy link
Contributor

this is apparently an issue for me as well.

python 2.7.9
spyder 2.3.4

@ccordoba12
Copy link
Member

@mikofski, what's your IPython version?

@mikofski
Copy link
Contributor

ipython 3.1.0

background

I have a python extension that runs the MATLAB Common Runtime in a child process using multiprocessing. This is convenient because it lets me run the MCR multiple times, whereas from the main process I can only run the MCR once - because the MCR must be initialized and can only be initialized and terminated once per process. Leaving it running for a long time is risky because the MATLAB memory manager is unpredictable.

methods that work in spyder

  • a normal python console

  • running a script in a dedicated python console with commands wrapped in

    if __name__ == "__main__":
        do child proc stuff
    
  • run in current python console and selecting python console, also with protection for __main__

  • running a script with __main__ protection in current IPython console

methods that fail in spyder

  • using the Ipython console hangs, no visible traceback. I must terminate the console and restart kernel.

@ccordoba12 ccordoba12 modified the milestones: v3.1, v3.0 Jul 13, 2015
@rhjmoore
Copy link

This is definitely a problem on my Windows machines. I haven't had the same problem on Linux.

@ccordoba12
Copy link
Member

Multiprocessing is know to not work well with the IPython console, but I think that's beyond Spyder.

@yanwu26
Copy link

yanwu26 commented Aug 29, 2017

Hello, I know this is an older thread but I have this problem as well. What is a suggested alternative?

@mikofski
Copy link
Contributor

@yanwu26 use the basic Python console instead of ipython kennel and it should work fine

@goanpeca
Copy link
Member

This works fine on latest Master and Mac

@dalthviz or @jnsebgosselin, could you guys check on Win ?

from multiprocessing import Pool


def multi_fn(x):
    return x**2

eg = [1,2,3,4,5,6,7]

pool = Pool()
out = pool.map(multi_fn,eg)
pool.close()
pool.join()

@dalthviz
Copy link
Member

@goanpeca it hangs for me on Windows

@jnsebgosselin
Copy link
Member

This is a problem specific to Windows OS.

@goanpeca
Copy link
Member

Indeed.

Some reference material: https://medium.com/@grvsinghal/speed-up-your-python-code-using-multiprocessing-on-windows-and-jupyter-or-ipython-2714b49d6fac

Any ideas on how we could detect this and warn the user?

@goanpeca
Copy link
Member

goanpeca commented Nov 30, 2019

Do you think we could do something here for windows as well @impact27 ?

Warn the users that they need to do something special at least?

@impact27
Copy link
Contributor

The easiest way would be to subclass Pool() in spydercustomize to print a warning when created on windows. And add an option to silence the warning. Like:

Warning: `multiprocessing.Pool` is known to hang in the console on windows. Please call this in a `if __name__ == "__main__":` statement. You can disable this warning by ...

@ccordoba12
Copy link
Member

@impact27, that's a good compromise, but how can we detect if Pool() is being called inside __main__ or not?

@impact27
Copy link
Contributor

impact27 commented Nov 30, 2019 via email

@goanpeca goanpeca modified the milestones: not sorted, v5.0beta1 Dec 4, 2019
@impact27
Copy link
Contributor

impact27 commented Dec 4, 2019

Apparently multiprocessing should display a warning itself:
image
Could this issue be assigned to someone who works on windows?

@goanpeca goanpeca removed this from the v5.0beta1 milestone Feb 18, 2020
@ccordoba12 ccordoba12 added this to the v5.0alpha2 milestone Aug 5, 2020
@ccordoba12 ccordoba12 modified the milestones: v5.0alpha2, v5.0alpha3 Nov 12, 2020
@ccordoba12 ccordoba12 modified the milestones: v5.0alpha3, v5.0alpha4 Jan 8, 2021
@ccordoba12 ccordoba12 modified the milestones: v5.0alpha4, v5.0alpha5 Feb 14, 2021
@ccordoba12 ccordoba12 modified the milestones: v5.0alpha5, v5.0alpha6 Feb 23, 2021
@ccordoba12 ccordoba12 modified the milestones: v5.0alpha6, v5.0beta1 Mar 19, 2021
@ccordoba12 ccordoba12 modified the milestones: v5.0.0, v5.x Apr 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants