473,654 Members | 3,308 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.setdefau lttimeout(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(curr enturl)
exit
Jul 18 '05 #1
2 1432
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
3039
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
338
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
1433
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 topmost childform that already exists is also maximized. Furthermore, if I maximize one form, I don't want all the other forms to be maximized, and the same thing goes for 'restoring' forms to their original size. Any ideas?
24
4734
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 OLTP DB to a the target Operational Data Store. This is still in development so both DB's reside on the same machine for convenience. The stored proc runs successfully from within Query analyzer and this holds true on the following platforms: XP...
2
2360
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 experiencing strange behaviour with Processes that are created when I create a DAO Database Object with the following line: Set m_ResDatabase = DBEngine.Workspaces(0).OpenDatabase(strDSN, False,
6
1731
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 same machine (change of the ports, different paths to logs, ...)? Thanks in advance for your answers.
1
1753
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 code: private void button1_Click(object sender, System.EventArgs e) { Word.ApplicationClass w1 = new Word.ApplicationClass();
0
1063
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 instead stay running, 'just sitting there', exhibiting a number of unusual properties: Memory usage about 68K - normal .NET processes take up multi-Megabytes of memory. Process has a single thread in the Wait:Suspended state. The thread's...
1
3557
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 many of the others in the class. We haven't been exposed to any Unix and the professor hasn't, yet, said much more than the book, which is no help at this point. From what I've figured out and what I've blindly seen on the net and hoped would...
0
8294
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8709
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8494
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8596
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4297
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1924
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1597
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.