[go: up one dir, main page]

Menu

[13581b]: / LockedPrint.py  Maximize  Restore  History

Download this file

31 lines (23 with data), 577 Bytes

 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
#!/usr/bin/env python
# -*- coding: UTF 8 -*-
import threading
import time
def locked_print(*args):
strings = map(str, args)
string = " ".join(strings)
print_lock.acquire()
print string
print_lock.release()
print_lock = threading.Lock()
class SocketRecvThread(threading.Thread):
def __init__(self, socket):
threading.Thread.__init__(self)
self.running = True
self.socket = socket
def run(self):
while self.running:
socket_news = self.socket.recv(4096)
if socket_news != "":
locked_print(socket_news)
def quit(self):
self.running = False