简体   繁体   中英

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. Here's my 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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