473,403 Members | 2,284 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,403 software developers and data experts.

Returning from socket.accept and threading issues.

Hello,
I'm trying to write a fairly simple network program. The main thread spawns
a thread which creates a listener socket and then calls socket.accept on
it. socket.accept blocks indefinantly. My problem is that when the main
thread determines that it is time to quit, how do I get the spawned thread
to exit? Preferably I'd like the spawned thread to return from
socket.accept when the main thread tells it to and then check a shared
varible to determine if it should die or call socket.accept again.

Any advice on this stuff would be greatly appreciated.

My temporary solution is to poll (via select.select) the listening socket
for input before socket.accept is called. I don't like this method because
it eats up CPU time.

Thanks for the help.

Jul 18 '05 #1
2 2366
"Christopher J. Bottaro" <cj*******@alumni.cs.utexas.edu> wrote in message news:<ma**************************************@pyt hon.org>...
Hello,
I'm trying to write a fairly simple network program. The main thread spawns
a thread which creates a listener socket and then calls socket.accept on
it. socket.accept blocks indefinantly. My problem is that when the main
thread determines that it is time to quit, how do I get the spawned thread
to exit? Preferably I'd like the spawned thread to return from
socket.accept when the main thread tells it to and then check a shared
varible to determine if it should die or call socket.accept again.

Any advice on this stuff would be greatly appreciated.

My temporary solution is to poll (via select.select) the listening socket
for input before socket.accept is called. I don't like this method because
it eats up CPU time.
If you call select with a short timeout eg:

select.select( [], [], [], 2.0 )

it uses almost no CPU.
Thanks for the help.


Regards, Paul Clinch
Jul 18 '05 #2
"Christopher J. Bottaro" <cj*******@alumni.cs.utexas.edu> wrote in message news:<ma**************************************@pyt hon.org>...
Hello,
I'm trying to write a fairly simple network program. The main thread spawns
a thread which creates a listener socket and then calls socket.accept on
it. socket.accept blocks indefinantly. My problem is that when the main
thread determines that it is time to quit, how do I get the spawned thread
to exit? Preferably I'd like the spawned thread to return from
socket.accept when the main thread tells it to and then check a shared
varible to determine if it should die or call socket.accept again.

Any advice on this stuff would be greatly appreciated.

My temporary solution is to poll (via select.select) the listening socket
for input before socket.accept is called. I don't like this method because
it eats up CPU time.

Thanks for the help.

Look here:

http://groups.google.com/groups?hl=e...ogle.com#link4
Jul 18 '05 #3

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

Similar topics

0
by: Daniel T. | last post by:
The code below fails. Socket.accept blocks inside the thread and doesn't let go, even after the socket was closed. From the error presented, the socket never actually closes. I realize that the...
2
by: Gonçalo Rodrigues | last post by:
Hi, My setup is the following: I have socket s from which I want to read and write. So I made the following set up: There is a thread whose only job is to read. Any data read (from recv call)...
8
by: simon place | last post by:
Spent some very frustrating hours recoding to find a way of closing a server socket, i'd not thought it would be any problem, however, after complete failure and as a last resort, i looked at the...
5
by: zxo102 | last post by:
Hi, I am doing a small project using socket server and thread in python. This is first time for me to use socket and thread things. Here is my case. I have 20 socket clients. Each client send a...
2
by: mumebuhi | last post by:
I am having problem to kill the following script completely. The script basically does the following. The main thread creates a new thread, which does a completely useless thing, and then starts...
0
by: mumebuhi | last post by:
I removed my previous post about this topic because I apparently have pasted the wrong code. Sorry for the confusion and thanks for being patient. I am having problem to kill the following...
2
by: darthghandi | last post by:
I am trying to pass a socket object when an event is signaled. I have successfully bound to a network interface and listened on a port for incoming connection. I have also been able to accept...
7
by: Guy Davidson | last post by:
Hi Folks, I'm having some issues with an small socket based server I'm writing, and I was hoping I could get some help. My code (attached below) us supposed to read an HTTP Post message...
0
by: Jean-Paul Calderone | last post by:
On Sat, 23 Aug 2008 02:25:17 +0800, Leo Jay <python.leojay@gmail.comwrote: No - it's just what I said. create_socket creates one socket and passes it to read_socket and write_socket. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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:
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.