-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsocket_thread.py
More file actions
39 lines (30 loc) · 1.05 KB
/
socket_thread.py
File metadata and controls
39 lines (30 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import logging
import wx
import socket
import time
from threading import Thread
log = logging.getLogger(__name__)
EVT_DATA_RECEIVED = wx.NewId()
class SocketThread(Thread):
BUFFER_SIZE = 1024
def __init__(self, notify_window):
Thread.__init__(self)
log.info("SocketThread init")
self.notify_window = notify_window
self.socket = notify_window.socket
self.__shutdown__ = False
def run(self):
log.info("run(BUFFER_SIZE=%s)" % self.BUFFER_SIZE)
while not self.__shutdown__:
try:
data = self.socket.recv(self.BUFFER_SIZE, socket.MSG_DONTWAIT)
log.info("OnReceive(%s)" % repr(data))
continue
except socket.error, ex:
#socket.error: [Errno 11] Resource temporarily unavailable
if ex.errno == 11:
log.debug("OnReceive: " + str(ex))
else:
raise
time.sleep(1)
#~ log.debug("wating for data...")