Ich habe ein Problem mit einem Programm, dass ich gerade schreibe. Es ist ein eifacher P2P chatclient/server mit threading. Das Problem, dass ich habe, ist, dass ich das Programm nicht aus "Run" von IDLE starten kann, da sich dann der PC aufhängt. Mache ich aber einen doppleclick auf die chatclient.py läuft das Programm ohne probleme (bisher nur über localhost xD). Lasse ich den Debugger aber in IDLE laufen, kommen ein paar seltsame fehler:
Code: Alles auswählen
Traceback (most recent call last):
File "C:\Python25\lib\idlelib\Debugger.py", line 67, in run
return self.idb.run(*args)
File "C:\Python25\lib\bdb.py", line 366, in run
exec cmd in globals, locals
File "D:\python\testxD.py", line 50, in <module>
blaServer().start()
File "C:\Python25\lib\threading.py", line 394, in __init__
assert group is None, "group argument must be None for now"
File "C:\Python25\lib\threading.py", line 394, in __init__
assert group is None, "group argument must be None for now"
File "C:\Python25\lib\bdb.py", line 48, in trace_dispatch
return self.dispatch_line(frame)
File "C:\Python25\lib\bdb.py", line 66, in dispatch_line
self.user_line(frame)
File "C:\Python25\lib\idlelib\Debugger.py", line 21, in user_line
self.gui.interaction(message, frame)
File "C:\Python25\lib\idlelib\Debugger.py", line 186, in interaction
self.show_variables(1)
File "C:\Python25\lib\idlelib\Debugger.py", line 299, in show_variables
lv.load_dict(ldict, force, self.pyshell.interp.rpcclt)
File "C:\Python25\lib\idlelib\Debugger.py", line 455, in load_dict
svalue = self.repr.repr(value) # repr(value)
File "C:\Python25\lib\repr.py", line 24, in repr
return self.repr1(x, self.maxlevel)
File "C:\Python25\lib\repr.py", line 34, in repr1
s = __builtin__.repr(x)
File "C:\Python25\lib\threading.py", line 416, in __repr__
assert self.__initialized, "Thread.__init__() was not called"
AssertionError: Thread.__init__() was not called
Code: Alles auswählen
import threading
from socket import *
import time
#----------------SERVER CLASS----------------
class blaServer ( threading.Thread ):
def run ( self ):
host = "localhost"
port = 33333
buff = 512
addr = (host,port)
ServerSocket = socket(AF_INET,SOCK_DGRAM)
ServerSocket.bind(addr)
print "Server started"
while 1:
data,addr = ServerSocket.recvfrom(buff)
if data:
print data
if data.endswith("Stop Now"):
ServerSocket.close()
print "Server shut down"
time.sleep(1)
break
#----------------CLIENT CLASS----------------
class blaClient ( threading.Thread ):
def run ( self ):
name = "LunarEffect"
host = "localhost"
port = 33333
buff = 512
addr = (host,port)
ClientSocket = socket(AF_INET,SOCK_DGRAM)
print "Client started"
print "Connection to", host, "on port", port
while (1):
data = raw_input()
if data:
data = name+" says: "+data
ClientSocket.sendto(data,addr)
if data.endswith("Stop Now"):
ClientSocket.close()
print 'Client shut down'
time.sleep(1)
break
#----------------MAIN XD----------------
blaServer().start()
time.sleep(0.1)
blaClient().start()