From: Ivan P. <ipo...@ma...> - 2017-07-22 08:01:48
|
Hello all! We are using jython heavily from Java application in multiple threads. This didn't cause any problems in 2.7.1b3 and earlier versions. After upgrading to 2.7.1 we faced the following: a simple call to datetime.strptime(...) or json.loads(...) can lead to "'org.python.modules.sre.MatchObject' object has no attribute..." error. As I suspect, this is related to the fact that RegexObject is not thread-safe anymore. It never was in Java, and never promised to be in Python, though in earlier versions of Jython this was possible: ############################################## import thread import re import time REGEX = re.compile('((?:foo|bar)+)(\d*)E?') def parse(line): m = REGEX.search(line) if m.groups(): print m.group(1) thread.start_new_thread(parse,('foofoofoofoofoofoofoofoofoo234',)) thread.start_new_thread(parse, ('foobarbarbarbarbarbarbarfoo4E',)) .... thread.start_new_thread(parse, ('foobarbarbarbarbarbarbarfoo4E',)) time.sleep(1) ############################################### In Jython 2.7.1 this (sometimes! you might need to run this script a couple of times) cause "'MatchObject' object has no attribute" errors. Instead of calling shared RegexObject one can simply do this: def printtime(time): print datetime.datetime.strptime(time, '%Y-%m-%dT%H:%M:%S') thread.start_new_thread(printtime, ('2017-07-01T11:11:11',)) ... thread.start_new_thread(printtime, ('2017-07-01T11:11:11',)) The same with json.loads. OK, we never share RegexObjects between threads in our code. But we cannot refuse to use json.loads and datetime.strptime! This became a major issue for us (http://bugs.jython.org/issue2609). What would you suggest? How can we help to solve this? Regards, Ivan Ponomarev |