Debugging with multiprocess causes exception in Pycharm
Hello,
I am seeing an exception when debugging code that uses the multiprocess library -- it looks like an exception will get thrown in Pycharm when the child process terminates.The script will run fine when running from the command line.
I have put together a small sample the reproduces the error that I see -- this is on Pycharm 2018-3.4, Python 3.7. I am also using a virtual environment.
When debugging under Pycharm, I see the following error:
pydev debugger: process 6684 is connecting
Worker
Worker
Traceback (most recent call last):
File "<..>/apps/pycharm-2018.3.4/helpers/pydev/pydevd.py", line 1741, in <module>
main()
File "<..>/apps/pycharm-2018.3.4/helpers/pydev/pydevd.py", line 1735, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "<..>/apps/pycharm-2018.3.4/helpers/pydev/pydevd.py", line 1135, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "<..>/apps/pycharm-2018.3.4/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "<..>PycharmProjects/multiproc/test.py", line 25, in <module>
p.join()
File "/usr/lib64/python3.7/multiprocessing/process.py", line 140, in join
res = self._popen.wait(timeout)
File "/usr/lib64/python3.7/multiprocessing/popen_fork.py", line 48, in wait
return self.poll(os.WNOHANG if timeout == 0.0 else 0)
File "/usr/lib64/python3.7/multiprocessing/popen_fork.py", line 28, in poll
pid, sts = os.waitpid(self.pid, flag)
KeyboardInterrupt
Here is my sample code:
from multiprocessing import Process
def worker():
"""worker function"""
print('Worker')
return
class TestProcess(Process):
def __init__(self):
super(TestProcess, self).__init__()
def run(self):
print('Worker')
return
if __name__ == '__main__':
jobs = []
for i in range(5):
p = TestProcess()
jobs.append(p)
for p in jobs:
p.start()
p.join()
Please sign in to leave a comment.
Hi,
The issue did not reproduce for me - the code is executed in debug mode without interruptions. Do you place any break points, and where?
I am experiencing this error as well. I can reproduce with the code snippet from OP.
PyCharm 2019.1.1 (Community Edition)
Build #PC-191.6605.12, built on April 3, 2019
JRE: 11.0.2+9-b159.34 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.15.0-46-generic
(Edited for clarification)
Please ensure that:
1. Attach to subprocess automatically is enabled in "File | Settings | Build, Execution, Deployment | Python Debugger"
2. Try removing "on termination" policy, see below screenshot:
Tried both suggestions but no change in behaviour
I was curious whether this behaviour depends on the Python version, and it does:
This happens with Python 3.7. I switched to 3.6 and the KeyboardInterrupt is gone and the behaviour is as expected. Back to 3.7 and the error occurs again.
To be more specific: This is 3.7.2 against 3.6.7
We have a few issues, I suspect that most likely you're hitting this one:
https://youtrack.jetbrains.com/issue/PY-34436
But also take a look at
https://youtrack.jetbrains.com/issue/PY-16301
https://youtrack.jetbrains.com/issue/PY-34436
@Maarten Rietbergen
Have you reproduced the issue using the code snippet from OP post? If not, can you please provide the snippet to reproduce?
I reproduced the issue using the code snippet from OP.
Dear Jetbrains,
clearly this is a problem, are you working on it?
I'm also running into this problem using python 3.7 and pycharm 2019.3.1
I believe this needs some attention. It is extremely difficult to debug issues with multiprocessing with a working debugger.
I am having to restart / remove checkpoints every five minutes to get it working.