home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- from win32pipe import *
- from win32file import *
- from win32event import *
- import pywintypes
- import win32api
- import winerror
- import sys
- import os
- import traceback
- verbose = 0
-
- def CallPipe(fn, args):
- ret = None
- retryCount = 0
- while retryCount < 8:
- retryCount = retryCount + 1
-
- try:
- return apply(fn, args)
- continue
- except win32api.error:
- (rc, fnerr, msg) = None
- if rc == winerror.ERROR_PIPE_BUSY:
- win32api.Sleep(5000)
- continue
- else:
- raise win32api.error, (rc, fnerr, msg)
- rc == winerror.ERROR_PIPE_BUSY
-
-
- None<EXCEPTION MATCH>win32api.error
- 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:
- 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):
- wait = CreateEvent(None, 0, 0, None)
- thread_waits.append(wait)
- thread.start_new_thread(stressThread, (server, numMessages, wait))
-
- WaitForMultipleObjects(thread_waits, 1, INFINITE)
-
-
- def main():
- global verbose
- import sys
- import getopt
- import string
- server = '.'
- thread_count = 0
- msg_count = 500
-
- try:
- (opts, args) = getopt.getopt(sys.argv[1:], 's:t:m:vl')
- for o, a in opts:
- if o == '-s':
- server = a
-
- if o == '-m':
- msg_count = string.atoi(a)
-
- if o == '-t':
- thread_count = string.atoi(a)
-
- if o == '-v':
- verbose = 1
-
- if o == '-l':
- testLargeMessage(server)
- continue
-
- msg = string.join(args)
- except getopt.error:
- msg = None
- 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 None
-
- 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)
-
-
- if __name__ == '__main__':
- main()
-
-