<commit_before>import importlib
from rosbridge_library.capability import Capability
import rospy
from datetime import datetime
import time
import threading

# try to import json-lib: 1st try usjon, 2nd try simplejson, else import standard python json
try:
    import ujson as json
    print "using ujson"
except ImportError:
    print "importing ujson failed"
    try:
        import simplejson as json
        print "using simplejson"
    except ImportError:
        print "importing simplejson failed"
        import json
        print "using python default json"

class ServiceList():
    """
    Singleton class to hold lists of received fragments in one 'global' object
    """
    class __impl:
        """ Implementation of the singleton interface """
        def spam(self):
            """ Test method, return singleton id """
            return id(self)

    __instance = None

    list = {}

    def __init__(self):
        """ Create singleton instance """
        if ServiceList.__instance is None:
            ServiceList.__instance = ServiceList.__impl()
            self.list = {}

        self.__dict__['_ServiceList__instance'] = ServiceList.__instance

    def __getattr__(self, attr):
        """ Delegate access to implementation """
        return getattr(self.__instance, attr)

    def __setattr__(self, attr, value):
        """ Delegate access to implementation """
        return setattr(self.__instance, attr, value)

    

class ReceivedResponses():
    """
    Singleton class to hold lists of received fragments in one 'global' object
    """
    class __impl:
        """ Implementation of the singleton interface """
        def spam(self):
            """ Test method, return singleton id """
            return id(self)

    __instance = None

    list = {}

    def __init__(self):
        """ Create singleton instance """
        if ReceivedResponses.__instance is None:
            ReceivedResponses.__instance = ReceivedResponses.__impl()
            self.list = {}

        self.__dict__['_ReceivedResponses__instance'] = ReceivedResponses.__instance

    def __getattr__(self, attr):
        """ Delegate access to implementation """
        return getattr(self.__instance, attr)

    def __setattr__(self, attr, value):
        """ Delegate access to implementation """
        return setattr(self.__instance, attr, value)

# service_template could hold a list of "request-objects" that can be identified by request id..
#   these objects could just make the json call to rosbridge-side and wait (blocking) until they receive their answer through a service response
#     that they receive from ServiceServer  (each service request would spawn one of those objects)
#     -> send_request_to_rosbridge-service-provider():   just passes the json-call
#     -> send_response_to_ros-client():                  just returns the response-content /data as if the answer never left ros
# PROBLEM with idea above:
#    -> we register a function in ros whose return gets passed to ros-side
#       ..if not returning from that function we have no way to give back data to the request
# SOLUTION_1:
#    -> use the loop with checking response_list like described in code below
class ROS_Service_Template( threading.Thread):
    service_request_timeout = 2 #seconds
    check_response_delay = 0.5 #seconds

    service_name = None
    service_node_name = None
    service_module = None
    service_type = None
    client_callback = None

    client_id = None
    service_id = None

    ros_serviceproxy = None

    request_counter = 0
    request_list = {}     # holds requests until they are answered (response successfully sent to ROS-client)  # probably not needed, but maybe good for retransmission of request or s.th. similar
    response_list = ReceivedResponses().list    # holds service_responses until they are sent back to ROS-client


    def __init__(self, client_callback, service_module, service_type, service_name, client_id):
        threading.Thread.__init__(self)
        
        print " ROS_Service_Template used to create a rosbridge-ServiceInstance"
        self.service_name = service_name
        self.service_module = service_module
        self.service_type = service_type
        self.client_id = client_id<commit_msg>set service_request_timeout back to 60 seconds; had 2s from timeout_tests..<commit_after>import importlib
from rosbridge_library.capability import Capability
import rospy
from datetime import datetime
import time
import threading

# try to import json-lib: 1st try usjon, 2nd try simplejson, else import standard python json
try:
    import ujson as json
    print "using ujson"
except ImportError:
    print "importing ujson failed"
    try:
        import simplejson as json
        print "using simplejson"
    except ImportError:
        print "importing simplejson failed"
        import json
        print "using python default json"

class ServiceList():
    """
    Singleton class to hold lists of received fragments in one 'global' object
    """
    class __impl:
        """ Implementation of the singleton interface """
        def spam(self):
            """ Test method, return singleton id """
            return id(self)

    __instance = None

    list = {}

    def __init__(self):
        """ Create singleton instance """
        if ServiceList.__instance is None:
            ServiceList.__instance = ServiceList.__impl()
            self.list = {}

        self.__dict__['_ServiceList__instance'] = ServiceList.__instance

    def __getattr__(self, attr):
        """ Delegate access to implementation """
        return getattr(self.__instance, attr)

    def __setattr__(self, attr, value):
        """ Delegate access to implementation """
        return setattr(self.__instance, attr, value)

    

class ReceivedResponses():
    """
    Singleton class to hold lists of received fragments in one 'global' object
    """
    class __impl:
        """ Implementation of the singleton interface """
        def spam(self):
            """ Test method, return singleton id """
            return id(self)

    __instance = None

    list = {}

    def __init__(self):
        """ Create singleton instance """
        if ReceivedResponses.__instance is None:
            ReceivedResponses.__instance = ReceivedResponses.__impl()
            self.list = {}

        self.__dict__['_ReceivedResponses__instance'] = ReceivedResponses.__instance

    def __getattr__(self, attr):
        """ Delegate access to implementation """
        return getattr(self.__instance, attr)

    def __setattr__(self, attr, value):
        """ Delegate access to implementation """
        return setattr(self.__instance, attr, value)

# service_template could hold a list of "request-objects" that can be identified by request id..
#   these objects could just make the json call to rosbridge-side and wait (blocking) until they receive their answer through a service response
#     that they receive from ServiceServer  (each service request would spawn one of those objects)
#     -> send_request_to_rosbridge-service-provider():   just passes the json-call
#     -> send_response_to_ros-client():                  just returns the response-content /data as if the answer never left ros
# PROBLEM with idea above:
#    -> we register a function in ros whose return gets passed to ros-side
#       ..if not returning from that function we have no way to give back data to the request
# SOLUTION_1:
#    -> use the loop with checking response_list like described in code below
class ROS_Service_Template( threading.Thread):
    service_request_timeout = 60 #seconds
    check_response_delay = 0.5 #seconds

    service_name = None
    service_node_name = None
    service_module = None
    service_type = None
    client_callback = None

    client_id = None
    service_id = None

    ros_serviceproxy = None

    request_counter = 0
    request_list = {}     # holds requests until they are answered (response successfully sent to ROS-client)  # probably not needed, but maybe good for retransmission of request or s.th. similar
    response_list = ReceivedResponses().list    # holds service_responses until they are sent back to ROS-client


    def __init__(self, client_callback, service_module, service_type, service_name, client_id):
        threading.Thread.__init__(self)
        
        print " ROS_Service_Template used to create a rosbridge-ServiceInstance"
        self.service_name = service_name
        self.service_module = service_module
        self.service_type = service_type
        self.client_id = client_id
{'fraction_non_alphanumeric': 0.07185142193847939, 'fraction_numerical': 0.002089378990133488, 'mean_word_length': 2.9199272065514106, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '377540', 'n_tokens_mistral': 2265, 'n_tokens_neox': 2164, 'n_words': 814}