How to execute a funcion callback as subprocess in python?
<p>I'm currently learning how to use subprocesses, for this (and some other) reasons
I've bought a book to learn how to work with subprocesses. It's a good book
and I'm not having troubles understanding it. In my book they start to explain
how to execute shell commands as subprocesses.</p>

<p>I had a programming problem I had for ages, and with the subprocesses, I could
be able to solve it <strong>but</strong> I need to execute a function callback as subprocess.</p>

<p>I have this code to echo something but it's a shell command:</p>

<pre><code>import subprocess

proc = subprocess.Popen(['echo', 'Hello, this is child process speaking'],
            stdout=subprocess.PIPE, shell=True)
out, err = proc.communicate()
print(out.decode('utf-8'))
</code></pre>

<p>I want this callback to be executed as a subprocess:</p>

<pre><code>def callb()
import time as t
print('2')
t.sleep(2)
    print('1')
t.sleep(2)
    print('0')
</code></pre>

<p>I just tried out to execute this callback like this (it was a simple naive idea):</p>

<pre><code>proc = subprocess.Popen(callb())
</code></pre>

<p>but this gives me the following error:</p>

<pre><code>Traceback (most recent call last):
  File "/root/testfile.py", line 6, in &lt;module&gt;
    proc = subprocess.Popen(callb())
  File "/usr/lib/python3.3/subprocess.py", line 818, in __init__
    restore_signals, start_new_session)
  File "/usr/lib/python3.3/subprocess.py", line 1321, in _execute_child
    args = list(args)
TypeError: 'NoneType' object is not iterable
</code></pre>

<p>The strange thing is, that it <strong>does</strong> execute the callback, but then it raises this error!
What did I do wrong?  Did I forget something?</p>