我在使用CRCMOD库获取CCITT CRC16检查的Python 3.4中编写代码时遇到问题。
那就是我的字符串:
a731986b1500087f9206e82e3829fe8bcffed5555efd00a100980000010000000100000009010013bb1d001e287107009b3000000300000088330000f427500077026309
Run Code Online (Sandbox Code Playgroud)
指定的crc值为1d7f
我的代码:
import crcmod
crc16 = crcmod.mkCrcFun(0x11021, 0x1d0f, False, 0x0000)
hex(crc16(b'a731986b1500087f9206e82e3829fe8bcffed5555efd00a100980000010000000100000009010013bb1d001e287107009b3000000300000088330000f427500077026309'))
Run Code Online (Sandbox Code Playgroud)
返回:7d67
我究竟做错了什么?
我正在尝试了解 Python 3 上的线程。我制作了一个示例代码:
import time
import threading
def myfunction(string,sleeptime,lock,*args):
count = 0
while count < 2:
#entering critical section
lock.acquire()
print(string, " Now sleeping after Lock acquired for ",sleeptime)
time.sleep(sleeptime)
print(string, " Now releasing lock and sleeping again.\n",time.ctime(time.time()))
lock.release()
#exiting critical section
time.sleep(sleeptime)
count+=1
#threading.Thread.daemon=True
if __name__!="__main__":
lock = threading.Lock()
try:
threading.Thread.start(myfunction("Thread Nº 1",2,lock))
threading.Thread.start(myfunction("Thread Nº 2",2,lock))
except:
raise
while 1:pass
Run Code Online (Sandbox Code Playgroud)
它部分起作用。当它到达 时while<2 loop,它返回错误:
Traceback (most recent call last):
File "python", line 22, in <module>
AttributeError: 'NoneType' …Run Code Online (Sandbox Code Playgroud)