473,395 Members | 1,941 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Processes with strange behavoir

Hi.

Today I created a script called load.py for using at the command line
written in Python 2.3.
This script should load as many websites as given on the comand line and
print them with a seperation string to stdout. The loading was done in
parallel. (I used processes for this.)

The script was started by the following command:

../load.py en 58746 http://www.python.com

Well, everything was fine. Then I wanted to load a second website and so I
started the script with the following command:

../load.py en 58746 http://www.python.com http://www.linux.org

The behaviour was strange: The last website (http://www.linux.org) was
loaded and printed twice.

Then I started the script for a third time with the following command:

../load.py en 58746 http://www.python.com http://www.linux.org
http://www.suse.com

The result was: First websites was loaded and shown once, second website
twice, and the third website was loaded and shown for four times!

(This behaviour occurs with ANY address given to the script...)
Does anybody know an answer to my problem???
Thank you.

Best regards

Markus Franz

(some information about my computer: Python 2.3, SuSE Linux 9.0 Pro with
Kernel 2.4)

--------------------------------------------------
My script:
--------------------------------------------------

#!/usr/bin/python

import urllib2, sys, socket, os, string

# set timeout
socket.setdefaulttimeout(4)

# function for loading and printing a website
def myfunction(url):
try:
req = urllib2.Request(url)
req.add_header('Accept-Language', sys.argv[1])
req.add_header('User-Agent', 'Mozilla/4.0 (compatible; MSIE 6.0;
Windows NT 5.1)')
f = urllib2.urlopen(req)
contents = f.read()
output = "\n---PI001---" + sys.argv[2] + '---PI001---' + '---PI002-'
+ sys.argv[2] + '::' + f.geturl() + '::' + sys.argv[2] + "-PI002---\n" +
contents
print output
del output
f.close()
del contents
del f
del req
except:
pass

# start processes
for currenturl in sys.argv:
if currenturl != sys.argv[0] and currenturl != sys.argv[1] and
currenturl != sys.argv[2]:
PID = os.fork()
if PID == 0:
myfunction(currenturl)
exit
Jul 18 '05 #1
2 1416
Markus Franz wrote:
Today I created a script called load.py for using at the command line
written in Python 2.3.
This script should load as many websites as given on the comand line and
print them with a seperation string to stdout. The loading was done in
parallel. (I used processes for this.)

The script was started by the following command:

./load.py en 58746 http://www.python.com

Well, everything was fine. Then I wanted to load a second website and so I
started the script with the following command:

./load.py en 58746 http://www.python.com http://www.linux.org

The behaviour was strange: The last website (http://www.linux.org) was
loaded and printed twice.

Then I started the script for a third time with the following command:

./load.py en 58746 http://www.python.com http://www.linux.org
http://www.suse.com

The result was: First websites was loaded and shown once, second website
twice, and the third website was loaded and shown for four times!

(This behaviour occurs with ANY address given to the script...)
Does anybody know an answer to my problem???


I think the structure of your script should be

import os, sys
for arg in sys.argv[1:]:
pid = os.fork()
if pid == 0:
print arg # placeholder for the download routine
break

As you have omitted the break statement, each child will complete the for
loop and thus continue to fork() for the remaining entries in sys.argv[1:].

Peter

Jul 18 '05 #2
"exit" -> doesn't do anything
"exit()" -> does something

Jeff

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Markus Franz | last post by:
Hi. I created a little script: for currenturl in sys.argv: pid = os.fork() if pid == 0: signal.alarm(10) do_something() # placeholder for the download and print routine
9
by: JennaS | last post by:
Hi. I was just wondering if you can fork a process in .NET like you would in C Thank Jenna
2
by: Eyvind W Axelsen | last post by:
Hi. I am creating an application (primarily in C#), with MDI child windows. What I would like to do, is to override the default behavoir that makes a newly createad child form maximized if the...
24
by: LineVoltageHalogen | last post by:
Greetings All, I was hoping that someone out there has run into this issue before and can shed some light on it for me. I have a stored procedure that essentially does a mini ETL from a source...
2
by: Chris | last post by:
I need to know exactly what VBA lines Create and Destroy SQL Server Processes - i.e. those visible in Enterprise Manager under Management > Current Activity > Process Info. Why? I am...
6
by: Jean-Guillaume LALANNE | last post by:
Hi, I am pretty new to the postgresql community. My question may seem a little bit strange but I'd like to know if it is possible to run 2 postgresql processes with 2 separate databases on the...
1
by: Paguro Bernardo | last post by:
Hi everybody, I'm encountering some problem in trying to activate more than one instance of Word from C#. To keep it simple, I have a stupid Form, with just a button in it and the following...
0
by: Innes MacKenzie | last post by:
I have an application (a .NET 2.0 windows service) which launches numerous short-lived processes (also a .NET 2.0 application). Occasionally, one or two of these processes will not run properly but...
1
by: jazon | last post by:
Let me start by saying this for an Operating Systems class. No, I don't expect the work to be done for me. The assignment is as follows: To be honest, I feel like a fish out of water, like...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.