graham / python_xid

Python Xid Implementation
MIT License
65 stars 25 forks source link

python_xid is not thread-safe #4

Closed wonderbeyond closed 5 years ago

wonderbeyond commented 6 years ago

I have made a commit to reveal this issue.

This commit added a test case that may failed occasionally. If you run the below test command multiple times, errors may occure:

$ py.test -sx
Exception in thread Thread-10:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/home/wonder/workspace/python_xid/xid_test.py", line 79, in worker
    threading.current_thread().ident, Xid().string()
  File "/home/wonder/workspace/python_xid/xid.py", line 95, in __init__
    id = generate_new_xid()
  File "/home/wonder/workspace/python_xid/xid.py", line 81, in generate_new_xid
    i = next(objectIDGenerator)
ValueError: generator already executing

We can make another commit to fix the issue...

PS: I don't know why py.test without -s option cannot reveal this issue.

graham commented 5 years ago

Sorry for the delay, your change is merged. (nice work!)