This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://pymotw.com/2/threading/ | |
import threading | |
import logging | |
logging.basicConfig(level=logging.DEBUG, format='(%(threadName)-10s) %(message)s', ) | |
class MyThread(threading.Thread): | |
def __init__(self, num): | |
threading.Thread.__init__(self) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://pymotw.com/2/threading/index.html | |
import threading | |
import logging | |
logging.basicConfig(level=logging.DEBUG, format='(%(threadName)-10s) %(message)s', ) | |
class MyThread(threading.Thread): | |
def run(self): | |
logging.debug('running') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://pymotw.com/2/threading/index.html | |
import threading | |
def worker(num): | |
print 'Worker: %s' % num | |
threads = [] | |
for i in range(5): | |
t = threading.Thread(target=worker, args=(i,)) | |
threads.append(t) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://pymotw.com/2/threading/index.html | |
import threading | |
def worker(): | |
print 'Worker' | |
threads = [] | |
for i in range(5): | |
t = threading.Thread(target=worker) | |
threads.append(t) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://www.ibm.com/developerworks/aix/library/au-threadingpython/ | |
import threading | |
import datetime | |
class ThreadClass(threading.Thread): | |
def run(self): | |
now = datetime.datetime.now() | |
print "%s says Hello World at time: %s\n" % (self.getName(), now) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
server_address = ('127.0.0.1', 5000) | |
client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
client_socket.connect(server_address) | |
message = 'Hi ...' | |
client_socket.send(message) | |
recv_message = client_socket.recv(1024) | |
print recv_message |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
server_address = ('127.0.0.1', 5000) | |
client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
message = 'Hi ...' | |
client_socket.sendto(message, server_address) | |
recv_message, server_address = client_socket.recvfrom(1024) | |
print recv_message, server_address |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
server_address = ('127.0.0.1', 5000) | |
server_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
server_socket.bind(server_address) | |
data, client_address = server_socket.recvfrom(1024) | |
server_socket.sendto(data, client_address) | |
print 'data:', data, 'client address', client_address | |
print 'sock name', server_socket.getsockname() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import sys | |
server_address = ('192.168.0.32', 5000) | |
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
client_socket.connect(server_address) | |
sys.stdout.write('>> ') | |
try: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import select | |
import sys | |
server_address = ('192.168.0.32', 5000) | |
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
server_socket.bind(server_address) | |
server_socket.listen(5) |