Comments (4)
python 哪里有管理线程的需求?最好贴出来哪条数据处理出错了
from jionlp.
python 哪里
此处做了判断,不确定是否为了避免重复执行 self._preprocess(),不过在代码中没有发现为 self.future_time 赋值的地方
https://github.com/dongrixinyu/JioNLP/blob/master/jionlp/gadget/time_parser.py#L778
from jionlp.
我为此写了一个测试用例,可以复现我说的问题
from concurrent.futures import ThreadPoolExecutor
from unittest import TestCase
from jionlp import TimeParser
class TestJioNLP(TestCase):
def setUp(self) -> None:
self.parse_time = TimeParser()
def test_thread_safe(self):
with ThreadPoolExecutor(max_workers=5) as executor:
futures = {executor.submit(self.parse_time, "2023年11月1日") for _ in range(5)}
for future in futures:
obj = future.result()
self.assertEqual(obj['time'], ['2023-11-01 00:00:00', '2023-11-01 23:59:59'])
这个用例在执行的时候会得到如下错误
test_jionlp.py:8 (TestJioNLP.test_thread_safe)
self = <tests.test_jionlp.TestJioNLP testMethod=test_thread_safe>
def test_thread_safe(self):
with ThreadPoolExecutor(max_workers=5) as executor:
futures = {executor.submit(self.parse_time, "2023年11月1日") for _ in range(5)}
for future in futures:
> obj = future.result()
test_jionlp.py:13:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../../../.pyenv/versions/3.11.4/lib/python3.11/concurrent/futures/_base.py:449: in result
return self.__get_result()
../../../../.pyenv/versions/3.11.4/lib/python3.11/concurrent/futures/_base.py:401: in __get_result
raise self._exception
../../../../.pyenv/versions/3.11.4/lib/python3.11/concurrent/futures/thread.py:58: in run
result = self.fn(*self.args, **self.kwargs)
../.venv/lib/python3.11/site-packages/jionlp/gadget/time_parser.py:768: in __call__
period_res, blur_time = self.parse_time_period(time_string, period_results_num=period_results_num)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <jionlp.gadget.time_parser.TimeParser object at 0x105a40450>
time_string = '2023年11月1日', period_results_num = None
def parse_time_period(self, time_string, period_results_num=None):
""" 判断字符串是否为 time_period,若是则返回结果,若不是则返回 None,跳转到其它类型解析。 """
has_weekday = False
if '工作日' in time_string:
has_weekday = True
> searched_res = self.period_time_pattern.search(time_string)
E AttributeError: 'TimeParser' object has no attribute 'period_time_pattern'
../.venv/lib/python3.11/site-packages/jionlp/gadget/time_parser.py:1169: AttributeError
Process finished with exit code 1
from jionlp.
哪能这么用,初始化是在初次调用 call 时候的。线程开启在__call__ 之前,初始化没做干净就开始解析,自然就报错了。
除非你手工执行 self.parse_time._preprocess()
函数
from jionlp.
Related Issues (20)
- [技术咨询] 关于多线程地址解析性能问题 HOT 1
- 时间解析问题 【年末、年初、月初、月末、年同期】相关
- [BUG]地址解析,文本:湖南永州市祁阳市梅溪镇湖南省祁阳县梅溪镇春光村十二组 解析不出来 HOT 1
- [BUG]解析20240307这种时间格式与预期不符 HOT 1
- 部分地址未能解析(2024.5.23)
- [BUG]特定地址解析失败 HOT 1
- [BUG]解析时间出现的两个问题
- 怎么更新地址表? HOT 3
- [BUG]最近 x 个月和最近 x 月两种返回不一致 HOT 1
- [BUG] 文本清洗链接无法去除 HOT 1
- [技术咨询]分词和词性标注在线体验地址是哪个? HOT 1
- 十一上午十一点十一 无法识别[BUG] HOT 2
- [BUG] 这个月、这一个月未能识别 HOT 1
- 地址解析错误 HOT 1
- [BUG] 路名中有“香港”会导致省市匹配错误 HOT 1
- 回译报错KeyError: 0 HOT 1
- 地址未识别
- 输入"明天下午一点参加下半年销售大会 " 提示ValueError: the string `明天下午一点参加下半年销售大会。` is illegal, because the hour-min-sec stringcan NOT be designated to a specific day.
- 地址解析能否新增返回行政编码功能
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jionlp.