Time.strptime function throwing error when streaming

I have a python function that works fine in "normal" mode, but throws an error when I run it in a stream function.

Function

def is_valid_date(date_value, is_mandatory): '''validate a date value. Return True if its a valid date http://stackoverflow.com/questions/2216250/how-can-i-validate-a-date-in-python-3-x ''' try: if is_mandatory == True: if len(date_value) != 8: return False y = date_value[0:4] m = date_value[4:6] d = date_value[6:8] date_value = d + "/" + m + "/" + y date_value = time.strptime(date_value, '%d/%m/%Y') return True else: if len(date_value) > 0: if len(date_value) != 8: return False y = date_value[0:4] m = date_value[4:6] d = date_value[6:8] date_value = d + "/" + m + "/" + y date_value = time.strptime(date_value, '%d/%m/%Y') return True else: return True except ValueError: return False 

Error:

 Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python3.2/threading.py", line 740, in _bootstrap_inner self.run() File "/home/lukik/apps/myapp/data_file/validate.py", line 97, in run is_valid, text_returned = is_valid_data_type(self.myText, dt_columns[colCounter].data_type, dt_columns[colCounter].mandatory) File "/home/lukik/apps/myapp/helper.py", line 27, in is_valid_data_type if is_valid_date(text_to_check, is_mandatory) != True: File "/home/lukik/apps/myapp/helper.py", line 91, in is_valid_date date_value = time.strptime(date_value, '%d/%m/%Y') AttributeError: _strptime_time 

Is it a date function that has an error, or is it a "race condition" in my queue and thread function?

+4
source share
1 answer

Apparently, there is an error when running the time.strptime() function in streaming mode in python 2.6 up to 3.2. I found a SO link that pointed me to bugs.python.org , which indicates an error.

Hacking according to @interjay's SO link is what you need to call time.strptime () before initializing your threads. So far this works for me. I don’t know if anyone has a better solution, since it seems more like a workaround than a solution.

+5
source

Source: https://habr.com/ru/post/1494272/


All Articles