473,800 Members | 2,731 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2383
"Christophe r J. Bottaro" <cj*******@alum ni.cs.utexas.ed u> wrote in message news:<ma******* *************** *************** *@python.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
"Christophe r J. Bottaro" <cj*******@alum ni.cs.utexas.ed u> wrote in message news:<ma******* *************** *************** *@python.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
1620
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 below is a basic Java idiom but how do you do the same thing in Python? import unittest import socket import threading
2
3284
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) is just passed to (some) Queue. This thread is "owned" by a second thread waiting on a Queue for write requests. The thread just pops these from the Queue, and calls the send method from the socket. This thread also takes care of closing the...
8
9290
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 python wrapper module for sockets, and found that the close command doesn't actually call the underlying close! this didn't seem right, so i added it, and my code now works simply and as expected. def close(self):
5
4774
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 set of sensor data per second to a socket server. The socket server will do two things: 1. write data into a file via bsddb; 2. forward the data to a GUI written in wxpython. I am thinking the code should work as follow (not sure it is feasible)...
2
4284
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 excepting for a connection via socket. # start import pickle import signal import simplejson import socket
0
1852
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 script completely. The script basically does the following. The main thread creates a new thread, which does a completely useless thing, and then starts excepting for a connection via socket. # start
2
4947
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 that connection and get the socket. I try to signal an event when this happens and pass that new socket object when the event happens, but when I try to pass the socket with this statement: ConnectionReceived(this, work); I get this exception in...
7
4021
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 coming from a power meter, parse it, and return a proper HTTP 200 Ok message. The problem is that the socket fails to send the entire message as one message, creating a fragmented message which the power meter then fails to read and accept.
0
2972
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. read_socket calls connect on the socket it is passed. write_socket calls accept on the socket it is passed. So a single socket has connect and accept called on it. Now, main does call create_socket twice, so this does happen to two sockets, but it's...
0
9690
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10251
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
10033
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...
0
9085
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7576
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
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2945
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.