Re: [Tutor] continuouse loop

2008-07-19 Thread Monika Jisswel
Thanks or your replies, in fact I need my server to recieve queries from
some 40 clients, process the recieved text (some calculations)  send a
response back to them, in my previouse application I used a database, (they
entered thier queries into the db  my calculating script looks at new
records in db every 2 minutes  inserts  the answers  into the db too so
that the users could see them on thier interface. but now I need to move to
a server/client design because at the time i had created this program I
didn't have much time  I had to put it into production.

Right now I am working on some code using the SOCKET module as it was the
only module that allows inter-process communication  was simple enough for
me  to understand how it works.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] continuouse loop

2008-07-19 Thread Martin Walsh
Monika Jisswel wrote:
 Thanks or your replies, in fact I need my server to recieve queries from
 some 40 clients, process the recieved text (some calculations)  send a
 response back to them, in my previouse application I used a database,
 (they entered thier queries into the db  my calculating script looks at
 new records in db every 2 minutes  inserts  the answers  into the db
 too so that the users could see them on thier interface. but now I need
 to move to a server/client design because at the time i had created this
 program I didn't have much time  I had to put it into production.

Assuming your 40 clients represent real human users, and not automated
processes, I almost always approach this kind of problem with a web
application, usually a cgi script or simple mod_python handler. That way
I can spend more time solving the problem at hand, and less on
client/server design details or client installation/upgrade scheduling.
But then browsers and web servers are very common in our environment.

 Right now I am working on some code using the SOCKET module as it was
 the only module that allows inter-process communication  was simple
 enough for me  to understand how it works.

In that case, you might want to have a look at the SocketServer module
also. http://www.python.org/doc/lib/module-SocketServer.html

HTH,
Marty
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] continuouse loop

2008-07-17 Thread Monika Jisswel
Would a program using a continuouse loop such as in this code take up
resources on the system if left for long period ?

import sys

 while 1:
 self.data = sys.stdin.readline()
 self.function_1(data)


What are my other options is I want to have a running program  other
programs communicate with it  get responses from it ?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] continuouse loop

2008-07-17 Thread Alan Gauld


Monika Jisswel [EMAIL PROTECTED] wrote

Would a program using a continuouse loop such as in this code take 
up

resources on the system if left for long period ?


Any running program takes up some resources but whether this
one would increase its resource usage over time, which I assume
is what you want to know, would depend on what it did with self.data
and what happened in self.function_1.

If function_1 did nothing that was resource intensive - like build
a big list in memory or open a new file each time it was called
(and not release it) - then it would be fine. But if function_1 stored
data in a list or opened a new comms port on each call then yes
it will eat up resources.


import sys


while 1:
self.data = sys.stdin.readline()
self.function_1(data)


What are my other options is I want to have a running program  
other

programs communicate with it  get responses from it ?


The trick to writing long running processes such as Windows services
and Unix daemons is to ensure they are either stateless (the create
use and free the needed resources in each operation) or utilise pools
(pre-allocated sets of resources that are allocated to a function as
needed and released by the function when done - if you run out of
pool you take a decision to enlarge the pool or to stop servicing
requests until resource becomes available - possibly using a
queue if instant response is not critical)

Thee are framweworks around, such as twisted, that help with these
tasks.

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] continuouse loop

2008-07-17 Thread Martin Walsh
Monika Jisswel wrote:
 Would a program using a continuouse loop such as in this code take up
 resources on the system if left for long period ?
 
 import sys
 
 while 1:
 self.data = sys.stdin.readline()
 self.function_1(data)

Not much, I would think, until something is written to stdin of this
program, and then it would depend on what function_1 does.

 What are my other options is I want to have a running program  other
 programs communicate with it  get responses from it ?

If I understand what you're asking, there are a few options outlined in
the python library reference, here:
http://docs.python.org/lib/ipc.html

I would add named pipes as another option for *nix, windows may have
something similar. And, depending on what you're trying to accomplish
maybe xmlrpclib, soappy, pyro, or perhaps even cgi.

HTH,
Marty

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor