Unusual Python interpreter problem with os.fork()

DLitgo ssj4_dave at hotmail.com
Fri Mar 6 14:00:03 CET 2009

Hello everyone,

I have a curious problem which I'm wondering if anyone here can shed
some light on. I'm basically just following along with a guide which
is going through some of the os module, and I'm running some examples
in the python interpreter on mac os x (accessed through terminal/

Basically all I did was use os.fork() which caused this strange

Macintosh:~ $ python
Python 2.5.1 (r251:54863, Jan 13 2009, 10:26:13)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> pid = os.fork()
>>> >>> pid
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'i' is not defined
>>> print 'what the hell?'
  File "<stdin>", line 1
    pdpit'htth l'?
SyntaxError: invalid syntax
>>> exit()
  File "<stdin>", line 1
SyntaxError: invalid syntax
>>> ^D

  File "<stdin>", line 1
    rn wa ehe'it(
SyntaxError: invalid syntax
>>> exit()
Macintosh:~ $

Sorry for any formatting issues with the above code/output, I don't
post on these mailing lists often and I usually just do it through
groups.google.com in my browser.

But as you can see something strange happens and things just get
garbled and unusual. I restarted bash to see if that was the issue (it
isn't) and I've also restarted my computer since I noticed this
happening (earlier today) and nothing different happens when I import
and use os.fork().

I did however enter these simple lines into an empty file and ran it
from bash which ended up going just fine:

#file: test.py
import os
pid = os.fork()
if pid == 0: os.execvp("ls", ["ls", "-l"])

More information about the Python-list mailing list