python multiprocessing Process is killed by http request if ipdb is imported
Asked Answered
W

0

4

It seems simply importing ipdb when making an http request wrapped in a multiprocessing Process instance causes the program to exit with no errors or messages.

The following script behaves very strangely:

from multiprocessing import Process
import requests
import ipdb

def spawn():

    print("before")
    r = requests.get("http://wtfismyip.com")
    print("after")

Process(target=spawn).start()

If you run this in terminal the output is simply before and you are back at your prompt. If you comment out import ipdb everything is fine and the request is successfully made.

  • Storing the Process instance in a variable and calling join() after start() didn't make a difference.
  • This happens in both Python 2.7.10 and 3.5.0.
  • It does not happen with the traditional pdb.
  • Other people here and here have also had this issue. In the former I am not sure if importing ipdb was the cause. In the latter it appeared to be an package/python version upgrade issue, but I checked that my iPython and ipdb are the current latest (4.0.0 and 0.8.1).

Can anyone explain why this is happening?

Wigeon answered 23/11, 2015 at 17:58 Comment(6)
I could not recreate this with Python 2.7.9 and IPython 2.3.0 on Linux. What OS are you on?Heteropterous
OS X Yosemite 10.10.5. Note that I saw this on 2.7.10 and 3.5.0, maybe something changed in 2.7.9 -> 2.7.10 that is causing this. No clue. I'm using iPython 4.0.0.Wigeon
I cannot explain, but you could find a workaround by only importing ipdb when you actually need it: import ipdb; ipdb.set_trace(). Keeping debug-related statements in the same place will make things easier when you'll need to remove them before pushing to production (if you ever do)Glyconeogenesis
Thanks or your comment, I get that. I'd like to understand why, or help raise attention to a bug if there is one in one of the packages.Wigeon
@ministry I am facing something similar in Python 2.7.12 / ipdb 0.11 on Ubuntu 16.04.4 as well. Not sure what is causing this. Have you figured out the reason for this? Please let me know.Fernandez
@Fernandez no sorry, I have not looked at this for a while.Wigeon

© 2022 - 2024 — McMap. All rights reserved.