473,383 Members | 1,748 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,383 software developers and data experts.

Thread error

Hi guys,
when I close the application I get the following error:

-----------------------------
Traceback (most recent call last):
File "main.py", line 88, in <module>
while exit : pass
KeyboardInterrupt
Unhandled exception in thread started by
Error in sys.excepthook:

Original exception was:
-----------------------------

This is the code:
-----------------------------
# Echo client program
import socket
import sys
import thread
import mtalk

HOST = '192.168.0.115' # The remote host
PORT = 3580 # The same port as used by the server

buff = ""
buffStatus = 0
s = None
exit = 1

############### keywordDataIn ###############
def keywordDataIn():
global buff, buffStatus, exit
talkmsg = mtalk.TalkMessage()
while exit:
line = sys.stdin.readline()
if line == 'quit\n':
exit = 0
break
elif line != '\n':
lock.acquire()
buff = talkmsg.Make(line)
buffStatus = 1
lock.release()
elif line == '\n':
pass

############### dataToServer ###############
def dataToServer():
global buff, buffStatus, exit
while exit:
if buffStatus == 1:
try:
lock.acquire()
s.sendall(buff)
buff = ""
buffStatus = 0
lock.release()
except: socket.error
pass # errore da controllare

############## dataFromServer ##############
def dataFromServer():
global exit
while exit:
data = s.recv(1024)
print 'Received', repr(data)


############### Main ###############
if __name__ == "__main__" :

for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC,
socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res

buffStatus = 0

try:
s = socket.socket(af, socktype, proto)
except socket.error, msg:
print("Unexpected error")
s = None
sys.exit(1)

try:
s.connect(sa)
print 'Connection ...'
except socket.error, msg:
print("The server was not reachable")
s.close()
s = None
sys.exit(1)

print 'Connected'

# mutex
lock = thread.allocate_lock()
thread.start_new_thread(keywordDataIn, ())
thread.start_new_thread(dataToServer, ())
thread.start_new_thread(dataFromServer, ())

while exit : pass

s.close()
-----------------------------
Tnx

Dec 3 '06 #1
3 2150
Tnx Dennis,
this is my first python program, so I don't know every modules :(

Anyway thank you so much for the suggestions, corrections and for the
whole program :)

Thank you

Dec 4 '06 #2
Hi Dennis,
I have another little problem with your source:

Traceback (most recent call last):
File "main.py", line 86, in <module>
kdi.join() # wait for kdi thread to exit NO CPU HOG BUSY LOOPS
File "d:\programmi\python25\lib\threading.py", line 549, in join
assert self.__started, "cannot join thread before it is started"
AssertionError: cannot join thread before it is started

I don't know what this means.
Now I try some experiment.
Tnx

Dec 4 '06 #3
Dennis Lee Bieber ha scritto:
Ah, sorry... Warned you that I didn't test...

Duplicate the block of lines with the .join() calls. Put this block
just before them, but after the threading.Thread calls, and change the
.join() to .start()
Tnx Dennis I resolved yesterday after the post.
I tried to delete the post :)
Anyway tnx

Dec 5 '06 #4

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

Similar topics

0
by: John Goerzen | last post by:
Hello, I am the author of OfflineIMAP, a program that currently is a heavy user of threads. For various reasons (see below), thread groups are something that is highly desirable for me in...
4
by: cedric | last post by:
hello, I encounter a problem using threads. I have a simple code to use a thread : cSurveillanceBorne = New clsThreadSurveillance _SurveillanceThread = New Thread(AddressOf...
9
by: mareal | last post by:
I have noticed how the thread I created just stops running. I have added several exceptions to the thread System.Threading.SynchronizationLockException System.Threading.ThreadAbortException...
0
by: bazzer | last post by:
hey, im trying to access a microsoft access database from an ASP.NET web application in visual basic 2003.NET. i get the following error when i try running it: Server Error in...
3
by: Gary Wessle | last post by:
#include <boost/thread/thread.hpp> #include <iostream> using namespace std; class waiter { public: waiter(); void waiting(); void preform();
4
by: jayesah | last post by:
Hi All, I am writting a Thread class with using pthread library. I have some problem in saving thread function type and argument type. How to make Thread class generic ? /* This is my global...
8
by: =?Utf-8?B?R3JlZyBMYXJzZW4=?= | last post by:
I'm trying to figure out how to modify a panel (panel1) from a backgroundworker thread. But can't get the panel to show the new controls added by the backgroundwork task. Here is my code. In...
5
by: Brian | last post by:
I have an file based asp.net application the creates a thread to do some background printing. It works fine but when the application is deployed on a web server, the following error occurs in the...
0
by: sauce | last post by:
Hi, Hm this error has gotten me really frustrated....I wrote a cgi script implementing threads using the threading module, but ran into these errors from my web server: Exception in thread...
34
by: Creativ | last post by:
Why does Thread class not support IDisposable? It's creating quite some problem. Namely, it can exhaust the resource and you have not control over it.
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
BarryA
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...
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...

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.