Problem with command line magic

I have a code that runs under windows command line. The code is part of a ML algorithm that trains a network and then generates test images sequentially. However when I try to run the exact same code in IPython kernel it always hang after a while (hang after some test images are generated). When I force the kernel to shut down somehow the remaining images got generated.

Example:
in command line:

    python main.py --model_name SRGAN --data_dir Registered_2D_slices\N6-N12 --sample_set APX134M2 --num_epochs 10 --scale_factor 2 --save_dir Models\test_model 

---->works

in ipython kernel:

! python main.py --model_name SRGAN --data_dir Registered_2D_slices\N6-N12 --sample_set APX134M2 --num_epochs 10 --scale_factor 2 --save_dir Models\test_model

---------> hangs

This really confuses me because aren’t these two supposed to be the same thing?

Here is the link to the code: https://github.com/bochaozhao/Super_resolution/blob/82d0b2ed190a9d65c069d00e0d4f0f1b337a0f35/main.py

Any help is appreciated.

It sounds like it is running but you aren’t getting the experience you expect.

In place of !python, using the %run IPython magic command documented here will result in a richer experience in the IPython kernel and Jupyter notebooks. In particular stderr is handled much better. Maybe you’ll get better completion notification handling, too?

Minor points:
Those two aren’t necessarily the same thing. Stackoverflow is littered with situations resulting from various installation approaches where which python on the command line and !which python in your IPython would produce different results.

Two minor points:
I was first going to suggest removing the space between ! and the python, but I tested in a few places and it didn’t seem to matter. However, I’d be careful because the shell commands can be overly sensitive to spaces in some versions. And the handling can differ slightly with the shell and IPython. Case in point, a format I was using to save files stopped working in IPython/Jupyter recently and the difference is a space. You now have to use %store foo >a.txt as documented here; with a space after the redirect, it now fails.