python interpreter from running docker container

Answered

I have a docker container image for generating a portable python environment and currently I am finding docker-compose to be the easiest way to configure PyCharm to use it (as it lets me configure volume bindings and environment variables on a project-wide level). There are some drawbacks with this approach though: 

  • The container is re-created every time I run a script which causes some slowdown
  • I can't (for whatever reason) launch two instances of the same configuration in parallel 
  • I can only output data to the display from one running instance at the time. So if I run two configurations in parallel that both produce a pyplot figure only one of them is shown

To get around these issues, would it instead be possible to connect PyCharm to a python interpreter inside an already running container? It seems to me like that would be a more handy solution. Something similar to doing `docker exec [running container] python3 /path/to/file` 

4 comments

Hi,

  • The container is re-created every time I run a script which causes some slowdown

This is how it currently works indeed.

  • I can't (for whatever reason) launch two instances of the same configuration in parallel 

Please check the corresponding option in your Run/Debug Configuration.

  • I can only output data to the display from one running instance at the time. So if I run two configurations in parallel that both produce a pyplot figure only one of them is shown

Not sure that I correctly understand. Do you mean that when run some code in parallel your plots are shown in one SciView window?
Screenshots are welcome.

>To get around these issues, would it instead be possible to connect PyCharm to a python interpreter inside an already running container? It seems to me like that would be a more handy solution. Something similar to doing `docker exec [running container] python3 /path/to/file`

Unfortunately not, this is not possible at the moment.

1

Hi Sergey, thanks for the response 

Great to know that there is a parameter for running multiple versions of the same config in parallel!

Some more explanation about the last point: by default plotting with matplotlib (or anything using the display) doesn't work when using a container-based interpreter. To get around this I have added `-e DISPLAY` and `-v /tmp/.X11-unix:/tmp/.X11-unix` (for linux) to the configuration.

But this seems to only allow one process to access the display, for example if I run two processes that each produce a plot only the first one is displayed. I'm not exactly sure why but I assume it has something to do with the .X11 folder already being mapped. I have disabled the SciView window so it's not related to that.  

Is there a technical reason as to why PyCharm cannot use an interpreter inside an already running container? Or could I expect it to be part of a future release? It would be a very nice feature to have

0

As far as I know it should work out of the box without additional manipulations. Could you please check this thread https://youtrack.jetbrains.com/issue/PY-27511#focus=streamItem-27-2605960-0-0?

Try using another Matplotlib backend or creating a new project. Does it work?

>Is there a technical reason as to why PyCharm cannot use an interpreter inside an already running container? Or could I expect it to be part of a future release? It would be a very nice feature to have

I am not aware of any technical reasons. I couldn't find any feature request for it. 

Please feel free to submit a feature request about it to our issue tracker using the link https://youtrack.jetbrains.com/issues/PY and let us know if you need any help.

0

I would like to be able to do this as well.  For instance, I have multiple processes running inside one container and it would be convenient to debug them separately.  

 

0

Please sign in to leave a comment.