Skip to content

Python3 多线程 更新token报错 #25

Open
@SJK132

Description

@SJK132

更新token以后 会报错

#Wechat Auto Reply logic
@itchatmp.msg_register(itchatmp.content.TEXT)
def text_reply(msg):

    if(msg['Content'].isdigit() and len(msg['Content']) == 5):
        return addjob(msg['FromUserName'],msg['Content'])

        WrongCRN = [u'好像没有这个课号呢!课号一般是5位数。',u'难受!没这个课号!再试试其他的吧!',u'逗我呢?',u'你**在给我free style吗?']
        return random.choice(WrongCRN)


@itchatmp.access_token
def producer(accessToken=None):
    while(1):
        if hasUpdated():
            itchatmp.send(str(datetime.datetime.now()),'oO3tH0e3rt_j85k3ASkztTBM8Mec')
            print('1')
        else:
            sleep(1)
            continue


#MultiThread

###### main auto reply ######
replyThread = threading.Thread(target=itchatmp.run)
# prevent Main Thread to continue
replyThread.setDaemon(True)
# start as Daemon
replyThread.start()

###### producer #####
producer = threading.Thread(target=producer)
producer.setDaemon(True)
producer.start()

replyThread.join()
producer.join()

每次都是Update Token以后 第二个thread 会报错

root@chi-us-vu:~/courserader# cat server/py_core/out.log
itchatmp started! press Ctrl+C to exit.
1
1
1
1
1
1
1
1
1
1
1
Access token updated
Exception in thread Thread-2:
Traceback (most recent call last):
  File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.5/threading.py", line 862, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.5/dist-packages/itchatmp-0.0.17-py3.5.egg/itchatmp/controllers/mpapi/base/common.py", line 150, in __access_token
    r = fn(*args, **kwargs)
  File "./wechat.py", line 47, in producer
    itchatmp.send(str(datetime.datetime.now()),'oO3tH0e3rt_j85k3ASkztTBM8Mec')
  File "/usr/local/lib/python3.5/dist-packages/itchatmp-0.0.17-py3.5.egg/itchatmp/server.py", line 82, in send
    return self.wrapped.send(msg, toUserName, mediaId)
  File "/usr/local/lib/python3.5/dist-packages/itchatmp-0.0.17-py3.5.egg/itchatmp/controllers/wrapped.py", line 7, in send
    self.core, msg, toUserName, mediaId)
  File "/usr/local/lib/python3.5/dist-packages/itchatmp-0.0.17-py3.5.egg/itchatmp/controllers/common.py", line 23, in determine_wrapper
    return tokenFn(mpFn)(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/itchatmp-0.0.17-py3.5.egg/itchatmp/controllers/mpapi/base/common.py", line 145, in __access_token
    updateResult = self.update_access_token()
  File "/usr/local/lib/python3.5/dist-packages/itchatmp-0.0.17-py3.5.egg/itchatmp/controllers/mpapi/base/common.py", line 173, in update_access_token
    return self._tokenFunction()
  File "/usr/local/lib/python3.5/dist-packages/itchatmp-0.0.17-py3.5.egg/itchatmp/controllers/mpapi/base/common.py", line 68, in _update_access_token
    self.maintain_access_token(r)
  File "/usr/local/lib/python3.5/dist-packages/itchatmp-0.0.17-py3.5.egg/itchatmp/controllers/mpapi/base/common.py", line 84, in maintain_access_token
    t = threading.Thread(target=auto_maintain_thread,
NameError: name 'auto_maintain_thread' is not defined

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions