Repository navigation
Description
i am getting the bellow trace when using parse function on multi threading application, i am not sure if this is happened because parse is not safe on multi threading applications or something else happened:
ERROR:root:*** An Error occured **** Traceback (most recent call last): File "Crawl.py", line 52, in worker self.init_request(url,details) File "Crawl.py", line 141, in init_request self.paginate(r,details) File "Crawl.py", line 135, in paginate self.parse(r,details) File "Crawl.py", line 153, in parse created_date = parse(ad['created'], settings={'PREFER_DATES_FROM': 'past'}) or datetime.datetime.now() File "/usr/local/lib/python2.7/dist-packages/dateparser/conf.py", line 80, in wrapper return f(*args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/dateparser/__init__.py", line 40, in parse data = parser.get_date_data(date_string, date_formats) File "/usr/local/lib/python2.7/dist-packages/dateparser/date.py", line 360, in get_date_data language, date_string, date_formats, settings=self._settings) File "/usr/local/lib/python2.7/dist-packages/dateparser/date.py", line 164, in parse return instance._parse() File "/usr/local/lib/python2.7/dist-packages/dateparser/date.py", line 174, in _parse date_obj = parser() File "/usr/local/lib/python2.7/dist-packages/dateparser/date.py", line 187, in _try_freshness_parser return freshness_date_parser.get_date_data(self._get_translated_date(), self._settings) File "/usr/local/lib/python2.7/dist-packages/dateparser/freshness_date_parser.py", line 117, in get_date_data date, period = self.parse(date_string, settings) File "/usr/local/lib/python2.7/dist-packages/dateparser/freshness_date_parser.py", line 70, in parse date, period = self._parse_date(date_string) File "/usr/local/lib/python2.7/dist-packages/dateparser/freshness_date_parser.py", line 102, in _parse_date date = self.now - td TypeError: unsupported operand type(s) for -: 'NoneType' and 'relativedelta'
Activity
asadurski commentedon Jan 28, 2017
Hello @Amr-alshroof. Yes, it's possible that multithreading is the issue (I will check it further).
In the meantime, can you give some examples of parsed strings?
Amr-alshroof commentedon Jan 29, 2017
@asadurski here are some examples.
Today 10:51
13 Dec
waqasshabbir commentedon Feb 24, 2017
@Amr-alshroof I tried reproducing the error following way.
On a side note, it's strange to see how self.now is set to
NoneType. Maybe you can share your code in a git snippet to enable us to have a deeper look?Thanks!
waqasshabbir commentedon Mar 13, 2017
@Amr-alshroof please re-open if you could reproduce this issue and a script snippet would be very helpful.
1ucy commentedon Mar 30, 2017
I'm having the same issue with it breaking on multi threading. It doesn't happen every time but randomly on some calls but not on others. Any chance this could be reopened?
1ucy commentedon Mar 30, 2017
Possibly related to issues with
self.now = datetime.now(self.get_local_tz())inparseas this stackoverflow question seems to imply.asadurski commentedon Mar 30, 2017
I gave it another try and I confirm I was able to reproduce that error. It happens when parsing relative dates only. I personally think that's because of the line https://github.com/scrapinghub/dateparser/blob/master/dateparser/freshness_date_parser.py#L110 which resets
self.nowtoNone, that might step on another thread's toes. Will dig further soon.1ucy commentedon Mar 31, 2017
Ah, that seems reasonable. For now I've just placed a lock around it but it's a little inelegant.
VMobileRecords commentedon Mar 31, 2019
Hi @asadurski, I encounter the same error when using QThreadPool and QRunnable in python - my intention is to have 6 threads running in parallel.
Is there a solution to this, or even a work-around?
Many thanks in advance!
diazagasatya commentedon Aug 15, 2019
I'm also running a multithread program with this and having the same issue. Try running the thread sequentially not in parallel may fix this issue.
Comment out reset in freshness_date_parser
AdrianAtZyte commentedon Aug 24, 2026
#885
serhii73 commentedon Aug 25, 2026
Adding the version detail, since several people are subscribed here and the closing pointer to #885 is easy to miss.
The crash in this report is
self.nowbeing instance state on the module-levelfreshness_date_parsersingleton: one thread reset it toNonewhile another was between assigning it and doingself.now - td. #885 (12cfa6f, merged 2021-02-18) removedself.nowfromdateparser/freshness_date_parser.pyaltogether and passes the value through as a parameter instead, so that frame can no longer exist.The first release containing it is dateparser 1.1.0 (2021-10-04) — it is not in 1.0.0.
I checked that against the releases rather than only the code. Running the shape of this report —
dateparser.parse(s, settings={'PREFER_DATES_FROM': 'past'})over the strings from it, 16 threads, 3000 calls, CPython 3.11:TypeError: unsupported operand type(s) for +: 'NoneType' and 'relativedelta'atfreshness_date_parser.py:138#441's verbatim snippet behaves the same way: 949/2000 failures on 1.0.0, 0/2000 on 1.1.0.
So if anyone still hits this traceback, it means dateparser < 1.1.0 and upgrading is the fix.
For completeness: #1346 (merged 2026-08-24, so it ships in the next release, not in 1.4.2) is not what fixed this crash — that was already gone. What it fixes is the thread-safety problems #885 did not touch:
KeyErrorfrom the size-limitedDictionarycaches (#1291), a locale's date order being written onto the sharedSettingsobject mid-parse, andsearch_dateswritingRELATIVE_BASEonto the shared default settings. Those are the reasons concurrent use was still unreliable after 1.1.0.