0

In Linux, if I execute this command in the terminal :

ipython  '/media/folder1/myscript.py'

it works. But, If I execute in IPython terminal :

import subprocess
cmd_list= ["ipython", '/media/folder1/myscript.py' ]
proc= subprocess.Popen(cmd_list)

I have this error :

cmd_list= ["ipython", filescript]
proc= subprocess.Popen(cmd_list)
Traceback (most recent call last):

  File "<ipython-input-47-66f9b0f2ed3f>", line 2, in <module>
    proc= subprocess.Popen(cmd_list)

  File "/home/linux1/anaconda2/lib/python2.7/subprocess.py", line 711, in __init__
    errread, errwrite)

  File "/home/linux1/anaconda2/lib/python2.7/subprocess.py", line 1343, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

Why sub-process cannot execute this terminal command ?

Mike Müller
  • 82,630
  • 20
  • 166
  • 161
tensor
  • 3,088
  • 8
  • 37
  • 71
  • 1) If you multiprocessing, it will fails on pickle.... 2) What about if you want to launch 5 process in parallel... – tensor Dec 27 '16 at 13:14
  • You use the dedicated multiprocessing module to properly execute the same bit of code as many times as you like. You'll only get pickle errors if you've designed your code incorrectly – Alastair McCormack Dec 27 '16 at 13:24
  • Are you aware that some types are not easily serializable (nested classes).... Have you ever done distributed calculation ? – tensor Dec 28 '16 at 17:29
  • In Python everything is an object so even the simplest user object will contain nested objects. Nested **classes** are nothing special. Both pickle just fine. I've done many multiprocessing projects which have shared data with other processes. Using Pickled objects isn't necessary for distributed calculation. How does forking in iPython give you distributed calculation? It sounds like you've made a number of assumptions. Perhaps you could explain your actual requirement in a new question – Alastair McCormack Dec 28 '16 at 18:05
  • Thanks, Sure, I have this issue in pickling some classes : https://github.com/cloudpipe/cloudpickle/issues/74 – tensor Dec 29 '16 at 06:50
  • Please ask your pickling question as a new Stackoverflow question - feel free to paste the link here so I can take a look. However, you've still not explained why the pickling problem is stopping you from using the multiprocessing module, as I originally suggested – Alastair McCormack Dec 29 '16 at 19:40

1 Answers1

1

You need to specify the full path for ipython. Type:

which ipython

in a terminal and use the path it tells you with subprocess:

cmd_list= ["/path/from/which/ipython", '/media/folder1/myscript.py']

Alternatively, you can try with shell=True:

subprocess.Popen(cmd_list, shell=True)

This might not be recommended, depending on your usage.

Community
  • 1
  • 1
Mike Müller
  • 82,630
  • 20
  • 166
  • 161