Update of /cvsroot/pywin32/pywin32/win32/Demos/service
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15490/Demos/service
Modified Files:
Tag: py3k
pipeTestService.py pipeTestServiceClient.py
Log Message:
Changes to build for Python 3.0
Index: pipeTestServiceClient.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/Demos/service/pipeTestServiceClient.py,v
retrieving revision 1.3
retrieving revision 1.3.4.1
diff -C2 -d -r1.3 -r1.3.4.1
*** pipeTestServiceClient.py 12 Mar 2003 12:44:01 -0000 1.3
--- pipeTestServiceClient.py 29 Aug 2008 04:59:25 -0000 1.3.4.1
***************
*** 37,86 ****
retryCount = retryCount + 1
try:
! return apply(fn, args)
! except win32api.error, (rc, fnerr, msg):
if rc==winerror.ERROR_PIPE_BUSY:
win32api.Sleep(5000)
continue
else:
! raise win32api.error, (rc, fnerr, msg)
! raise RuntimeError, "Could not make a connection to the server"
def testClient(server,msg):
if verbose:
! print "Sending", msg
data = CallPipe(CallNamedPipe, ("\\\\%s\\pipe\\PyPipeTest" % server, msg, 256, NMPWAIT_WAIT_FOREVER))
if verbose:
! print "Server sent back '%s'" % data
! print "Sent and received a message!"
def testLargeMessage(server, size = 4096):
if verbose:
! print "Sending message of size %d" % (size)
msg = "*" * size
data = CallPipe(CallNamedPipe, ("\\\\%s\\pipe\\PyPipeTest" % server, msg, 512, NMPWAIT_WAIT_FOREVER))
if len(data)-size:
! print "Sizes are all wrong - send %d, got back %d" % (size, len(data))
def stressThread(server, numMessages, wait):
try:
try:
! for i in xrange(numMessages):
r = CallPipe(CallNamedPipe, ("\\\\%s\\pipe\\PyPipeTest" % server, "#" * 512, 1024, NMPWAIT_WAIT_FOREVER))
except:
traceback.print_exc()
! print "Failed after %d messages" % i
finally:
SetEvent(wait)
def stressTestClient(server, numThreads, numMessages):
! import thread
thread_waits = []
! for t_num in xrange(numThreads):
# Note I could just wait on thread handles (after calling DuplicateHandle)
# See the service itself for an example of waiting for the clients...
wait = CreateEvent(None, 0, 0, None)
thread_waits.append(wait)
! thread.start_new_thread(stressThread, (server,numMessages, wait))
# Wait for all threads to finish.
WaitForMultipleObjects(thread_waits, 1, INFINITE)
--- 37,87 ----
retryCount = retryCount + 1
try:
! return fn(*args)
! except win32api.error as xxx_todo_changeme:
! (rc, fnerr, msg) = xxx_todo_changeme.args
if rc==winerror.ERROR_PIPE_BUSY:
win32api.Sleep(5000)
continue
else:
! raise win32api.error(rc, fnerr, msg)
! raise RuntimeError("Could not make a connection to the server")
def testClient(server,msg):
if verbose:
! print("Sending", msg)
data = CallPipe(CallNamedPipe, ("\\\\%s\\pipe\\PyPipeTest" % server, msg, 256, NMPWAIT_WAIT_FOREVER))
if verbose:
! print("Server sent back '%s'" % data)
! print("Sent and received a message!")
def testLargeMessage(server, size = 4096):
if verbose:
! print("Sending message of size %d" % (size))
msg = "*" * size
data = CallPipe(CallNamedPipe, ("\\\\%s\\pipe\\PyPipeTest" % server, msg, 512, NMPWAIT_WAIT_FOREVER))
if len(data)-size:
! print("Sizes are all wrong - send %d, got back %d" % (size, len(data)))
def stressThread(server, numMessages, wait):
try:
try:
! for i in range(numMessages):
r = CallPipe(CallNamedPipe, ("\\\\%s\\pipe\\PyPipeTest" % server, "#" * 512, 1024, NMPWAIT_WAIT_FOREVER))
except:
traceback.print_exc()
! print("Failed after %d messages" % i)
finally:
SetEvent(wait)
def stressTestClient(server, numThreads, numMessages):
! import _thread
thread_waits = []
! for t_num in range(numThreads):
# Note I could just wait on thread handles (after calling DuplicateHandle)
# See the service itself for an example of waiting for the clients...
wait = CreateEvent(None, 0, 0, None)
thread_waits.append(wait)
! _thread.start_new_thread(stressThread, (server,numMessages, wait))
# Wait for all threads to finish.
WaitForMultipleObjects(thread_waits, 1, INFINITE)
***************
*** 106,119 ****
testLargeMessage(server)
msg = string.join(args)
! except getopt.error, msg:
! print msg
my_name = os.path.split(sys.argv[0])[1]
! print "Usage: %s [-v] [-s server] [-t thread_count=0] [-m msg_count=500] msg ..." % my_name
! print " -v = verbose"
! print " Specifying a value for -t will stress test using that many threads."
return
testClient(server, msg)
if thread_count > 0:
! print "Spawning %d threads each sending %d messages..." % (thread_count, msg_count)
stressTestClient(server, thread_count, msg_count)
--- 107,120 ----
testLargeMessage(server)
msg = string.join(args)
! except getopt.error as msg:
! print(msg)
my_name = os.path.split(sys.argv[0])[1]
! print("Usage: %s [-v] [-s server] [-t thread_count=0] [-m msg_count=500] msg ..." % my_name)
! print(" -v = verbose")
! print(" Specifying a value for -t will stress test using that many threads.")
return
testClient(server, msg)
if thread_count > 0:
! print("Spawning %d threads each sending %d messages..." % (thread_count, msg_count))
stressTestClient(server, thread_count, msg_count)
Index: pipeTestService.py
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/Demos/service/pipeTestService.py,v
retrieving revision 1.6
retrieving revision 1.6.4.1
diff -C2 -d -r1.6 -r1.6.4.1
*** pipeTestService.py 31 Jan 2005 04:11:59 -0000 1.6
--- pipeTestService.py 29 Aug 2008 04:59:25 -0000 1.6.4.1
***************
*** 25,33 ****
import traceback
! import thread
def ApplyIgnoreError(fn, args):
try:
! return apply(fn, args)
except error: # Ignore win32api errors.
return None
--- 25,33 ----
import traceback
! import _thread
def ApplyIgnoreError(fn, args):
try:
! return fn(*args)
except error: # Ignore win32api errors.
return None
***************
*** 74,78 ****
hr, thisd = ReadFile(pipeHandle, 256)
d = d + thisd
! print "Read", d
ok = 1
except error:
--- 74,78 ----
hr, thisd = ReadFile(pipeHandle, 256)
d = d + thisd
! print("Read", d)
ok = 1
except error:
***************
*** 126,131 ****
try:
hr = ConnectNamedPipe(pipeHandle, self.overlapped)
! except error, details:
! print "Error connecting pipe!", details
CloseHandle(pipeHandle)
break
--- 126,131 ----
try:
hr = ConnectNamedPipe(pipeHandle, self.overlapped)
! except error as details:
! print("Error connecting pipe!", details)
CloseHandle(pipeHandle)
break
***************
*** 139,143 ****
else:
# Pipe event - spawn thread to deal with it.
! thread.start_new_thread(self.ProcessClient, (pipeHandle,))
num_connections = num_connections + 1
--- 139,143 ----
else:
# Pipe event - spawn thread to deal with it.
! _thread.start_new_thread(self.ProcessClient, (pipeHandle,))
num_connections = num_connections + 1
***************
*** 148,152 ****
while self.thread_handles:
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING, 5000)
! print "Waiting for %d threads to finish..." % (len(self.thread_handles))
WaitForMultipleObjects(self.thread_handles, 1, 3000)
# Write another event log record.
--- 148,152 ----
while self.thread_handles:
self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING, 5000)
! print("Waiting for %d threads to finish..." % (len(self.thread_handles)))
WaitForMultipleObjects(self.thread_handles, 1, 3000)
# Write another event log record.
|