forking and multiple executions of code

Donn Cave donn at drizzle.com
Wed May 14 02:28:12 EDT 2003


Quoth googlenews at ols.inorganic.org (Roy S. Rapoport):
...
| import os
| import time
| class Task:
|     def __init__(self, name):
|         self.name = name
|     def run(self):
|         print "Task: Entering %s.run." % self.name
|         self.__reallyrun()
|     def __reallyrun(self):
|         print "Task: Now in %s.__reallyrun" % self.name
|         try:
|             pid = os.fork()

Try
              sys.stdout.flush()
              pid = os.fork()

When your process forks, the data in output buffers is effectively
duplicated, so you will see it twice when the buffer is eventually
flushed.  It's different between the terminal and a file, because
output buffering follows different rules.

The code you posted actually returns from the fork, which is bad,
but I'm guessing that was just a transcription error.

	Donn Cave, donn at drizzle.com




More information about the Python-list mailing list