简体   繁体   English

如果 function 在当前单词处被阻塞或花费太长时间,请跳到下一个单词

[英]skip to the next word if the function is blocked at the current one or is taking too long

I want for my function to skip to the next word if the execution either doesn't work or take too long.如果执行不起作用或花费太长时间,我希望我的 function 跳到下一个单词。 Here's my function:这是我的 function:

def encode(word):
      return bc.encode([[word]],is_tokenized=True)

I tried the try/exepct like this:我尝试了这样的尝试/执行:

def bert(word):
        try:
            return bc.encode([[word]],is_tokenized=True)
        except:
         pass

But my code still stop running for some words.但是我的代码仍然停止运行一些单词。 Is there a function that can say to my function to pass to the next word if it takes too long?是否有一个 function 可以对我的 function 说如果需要太长时间才能传递到下一个单词?

I don't know what bc.encode is, but I googled it and if it's BertClient , according to this you can pass timeout=x to the constructor and I assume it will throw an exception if it takes more than that.我不知道bc.encode是什么,但我用谷歌搜索了它,如果它是BertClient ,根据这个你可以将timeout=x传递给构造函数,我认为如果它需要更多,它会抛出异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM