Hi,
I have one thread app using SocketServer and use server_forever() as a
main loop. All works fine, but now I need certain timer checking let's
say every 1 second something and stopping the main loop. So questions are:
-how to stop serve_forever
-how to implement timers
thx, alf 5 2005
alf wrote:
I have one thread app using SocketServer and use server_forever() as a
main loop. All works fine, but now I need certain timer checking let's
say every 1 second something and stopping the main loop. So questions are:
-how to stop serve_forever
Override serve_forever() and replace "while 1:" with something like
"while self.continue_flag:".
-how to implement timers
You could override get_request(), and use select.select() to wait for
either the socket to become readable (so the accept() won't block), or
a timeout to expire. If you are not already, use the threading or
forking
mixin so that the request handler won't stop everthing if it blocks.
--
--Bryan
alf wrote:
Hi,
I have one thread app using SocketServer and use server_forever() as a
main loop. All works fine, but now I need certain timer checking let's
say every 1 second something and stopping the main loop. So questions are:
-how to stop serve_forever
-how to implement timers
thx, alf
Do you really need a timer, or do you just want to check something
every second or so?
If the latter, then something like this would do it:
from time import time
INTERVAL = 1.0
RUN = True
while RUN:
# Get a time in the future.
T = time() + INTERVAL
# Serve requests until then.
while time() < T:
server.handle_request()
# Check whatever.
if check():
# Do something, for example, stop running.
RUN = False
HTH,
~Simon
Simon Forman wrote:
alf wrote:
Hi,
I have one thread app using SocketServer and use server_forever() as a
main loop. All works fine, but now I need certain timer checking let's
say every 1 second something and stopping the main loop. So questions are:
-how to stop serve_forever
-how to implement timers
thx, alf
Do you really need a timer, or do you just want to check something
every second or so?
If the latter, then something like this would do it:
from time import time
INTERVAL = 1.0
RUN = True
while RUN:
# Get a time in the future.
T = time() + INTERVAL
# Serve requests until then.
while time() < T:
server.handle_request()
# Check whatever.
if check():
# Do something, for example, stop running.
RUN = False
That alone does not work. If server.handle_request() blocks,
you don't get to the check(). You need some kind of timeout
in handle_request().
--
--Bryan br***********************@yahoo.com wrote:
....
>
That alone does not work. If server.handle_request() blocks,
you don't get to the check(). You need some kind of timeout
in handle_request().
--
--Bryan
Ach! You're right. I didn't consider that handle_request() might
block.. br***********************@yahoo.com wrote:
alf wrote:
>>I have one thread app using SocketServer and use server_forever() as a main loop. All works fine, but now I need certain timer checking let's say every 1 second something and stopping the main loop. So questions are: -how to stop serve_forever
Override serve_forever() and replace "while 1:" with something like
"while self.continue_flag:".
>> -how to implement timers
You could override get_request(), and use select.select() to wait for
either the socket to become readable (so the accept() won't block), or
a timeout to expire. If you are not already, use the threading or
forking
mixin so that the request handler won't stop everthing if it blocks.
thx for a suggestion, will try it out ... This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Olivier Hoarau |
last post by:
Hello,
I have build a client/server application with the socket module. The
server mades UDP broadcasting and the client only reads UDP broadcast
messages. All work fine.
Now I want to use for...
|
by: Ergin Aytac |
last post by:
I'm trying to run a script written in python and have some socket
connection problems. I cutted the origin script (more than 1000 lines)
so it is only the part of the connection and there is no...
|
by: Adil Hasan |
last post by:
Hello Fred,
I just ran across your question. I think that the following
code will work:
----- SERVER CODE ------
import SocketServer
import time
class...
|
by: missiplicity |
last post by:
Hi,
I am newbie to Python language and am taking my baby steps. I am
using Python2.4 from ActiveState on W2K. I am trying to create a simple
SocketServer program. Just adding the following 2 lines...
|
by: Paul Rubin |
last post by:
Let's say you have a SocketServer with the threading mix-in and you
run serve_forever on it. How can you shut it down, or rather, how can
it even shut itself down? Even if you use a...
|
by: Magnus Lycka |
last post by:
I have a socket server like below which I want to exit when
it's out of data. If I interrupt the client, I'll get a
broken pipe on the server side, and after a Ctrl-C, I can
restart the server...
|
by: rbt |
last post by:
I've read more about sockets and now, I have a better understanding of
them. However, I still have a few SocketServer module questions:
When used with SocketServer how exactly does...
|
by: Tomi Hautakoski |
last post by:
Hello,
I'm a Python newbie trying to figure out how to use SocketServer with
IPv6. I would like to set up a TCPServer working like below but how to
tell SocketServer I need to use AF_INET6?
...
|
by: eliben |
last post by:
Hello,
I have a small wxPython application. Today I was trying to add some
RPC capability to it, so I implemented an instance of
SimpleXMLRPCServer that runs in a separate thread when invoked...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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,...
| |