472,330 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,330 software developers and data experts.

To Kill a Process that is Accepting Connection on Socket

I removed my previous post about this topic because I apparently have
pasted the wrong code. Sorry for the confusion and thanks for being

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
import sys
import threading
import time

counter = 0

class WorkerThread(threading.Thread):
def run(self):
global counter
while True:
counter += 1

worker_thread = WorkerThread()

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('', 2727))

def cleanup(signal, frame):
print "die now"
signal.signal(signal.SIGINT, cleanup)

while True:
channel, details = server.accept()
stats = { 'key': "value" }
s = simplejson.dumps(stats)
# end

The way I can think of right now is to kill the script using Ctrl+C.
Hence, the signal handler in the code. However, the interpreter
$ python ex_server.py
die now
Traceback (most recent call last):
File "ex_server.py", line 33, in ?
channel, details = server.accept()
File "/usr/lib/python2.4/socket.py", line 169, in accept
sock, addr = self._sock.accept()
File "ex_server.py", line 28, in cleanup
File "<string>", line 1, in shutdown
socket.error: (128, 'Transport endpoint is not connected')

Does anybody know a better way to do this?

Thank you.


Oct 27 '06 #1
0 1717

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

Similar topics

by: Mike M | last post by:
Is it possible? In the parent process, I have a socket that binds, listens and then accepts new connections (which creates new sockets in the...
by: Jako Menkveld | last post by:
I'm building a relatively simple client-server app. One of the functions of the client is to notify the server when it terminates, this all works...
by: Mitch Mooney | last post by:
Im trying to make a wrapper and need to return the local port that the new connection/socket is being made on. The following code the RaiseEvent,...
by: I. Myself | last post by:
Suppose we spawn a child process with Popen. I'm thinking of an executable file, like a compiled C program. Suppose it is supposed to run for one...
by: Thomas Dybdahl Ahle | last post by:
Hi, I'm writing an application that connects to the internet. Something like this: for res in socket.getaddrinfo(host, port, 0,...
by: Richard Rossel | last post by:
Hi Fellows, I have a problem with process termination. I have a python code that apache runs through a django interface. The code is very simple,...
by: ppuniversal | last post by:
Hi everyone, I have made a client-server code in Linux. The server is running properly and is sitting at its accept() method. But the client is...
by: =?Utf-8?B?VGhlU2lsdmVySGFtbWVy?= | last post by:
Because C# has no native SSH class, I am using SharpSSH. Sometimes, for reasons I do not know, a Connect call will totally lock up the thread and...
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.