stress.py

Go to the documentation of this file.
00001 #!/usr/bin/python 
00002 ##
00003 # 
00004 #  @file test_dimc_service.py
00005 #  @brief An example of using a DIM service.
00006 #  This file contains an example for using a DIM service from python. A DimTask 
00007 #  object is at the same time the DIM service and client.
00008 #  Like for the DIM functions there are several steps needed to be taken:
00009 #    -# server creates a service
00010 #    -# server start 'serving' (dis_start_serving() )
00011 #    -# server updates the service
00012 #    -# client registers to a service
00013 #    -# client wait to be updated
00014 # 
00015 # @author Radu Stoica (Radu.Stoica@cern.ch)
00016 # \addtogroup examples
00017 # @{
00018 # 
00019 import sys
00020 from pydim import DEBUG, dic_cmnd_service, dis_update_service, dis_add_service, dic_info_service, dis_start_serving, dis_stop_serving, dic_release_service
00021 from time import sleep
00022 
00023 i = 0
00024 DEBUG=6    
00025 def stress_callback( *args):
00026     global i
00027     if i % 10000 == 0:        
00028        print "stress_callback: %d" % i
00029     i += 1
00030 
00031 def service_callback(tag):
00032     global i
00033     if i % 10000 == 0:
00034         print "stress service updated: %d" % i
00035     return (i,)    
00036       
00037 if __name__=='__main__':
00038     import sys
00039     n = 500000
00040     if len(sys.argv) > 1: n = int(sys.argv[1])
00041     si = dic_info_service("STRESS_SVC", "I", stress_callback)
00042     s = dis_add_service("PYSTRESS_SVC", "I", service_callback, 0)
00043     dis_start_serving("PYSTRESS") 
00044     while i < n or n == 0:
00045         res = dic_cmnd_service('STRESS_CMD', ('STRESSYOU!\0',), "C")
00046         dis_update_service(s)
00047         sleep(0.001)
00048     print "Stopping stress serving"
00049     dis_stop_serving()
00050     print "Stopping subscription"
00051     dic_release_service(si)
00052     print "Waiting for cleanup"
00053     sleep(5)
00054 
00055 

Generated on 5 Feb 2014 for PyDIM by  doxygen 1.4.7