Git Product home page Git Product logo

Comments (7)

greggzj avatar greggzj commented on June 27, 2024 1

hello @waukeerules , seems very interesting on your issue...
Frankly speaking, I am also fresh on this... unitl now what I only know is my following comments , @niccokunzmann please do not hesitate to point out if I make any mistakes... thanks in advance.

Take the first part of your log as an example, when calling self.queue.put((time.time() + seconds, func, args, kw)), priorityqueue use heapq and inside heapq it uses operator < to judge for the priority of current input tuple and previous input tuple.

When comparing the tuple, it first judges the first item of tuple : time.time() , it finds that current tuple and previous tuple has the same value for time.time() (really amazing here ...) , then it compare the second field of tuple , but this time func is a method and can not be compared , thus cause the TypeError: '<' not supported between instances of 'method' and 'method'. (Refer to python code of heapq.py (function _siftdown(heap, startpos, pos):)and here for more information.

So , for conclusion,
Seems that the reason why heapq complains: `TypeError: ' is that there is one tuple in previous priority queue with the same timestamp value of the current input one stored in priorityqueue! sounds really amazing...

Unfortunately, I do not know much about multithread either, but it seems that using current python standard library PriorityQueue and storing timestamp value in queue ( actually in python list) used as priority identifier may be not a good idea for they may be the same value .....

May be we can find another value used as identifier instead of time.time() stored in the priorityqueue. Or using a self implement priorityqueue to avoid such a problem^_^

what do u think @niccokunzmann

from python_dhcp_server.

waukeerules avatar waukeerules commented on June 27, 2024

I found that the errors only occur when multiple DHCP requests are initiated at the same exact time.

from python_dhcp_server.

greggzj avatar greggzj commented on June 27, 2024

Hello @waukeerules ,

I modify the dhcp.py , using a simple self-implement PriorityQueue class instead of the official one to avoid the timestamp same value problem. I test it on my bench it works. But for multiple device condition I need your help.

Could you please help me to have a try ? just unzip the file and replace the old one . Hoping for your feedback ! thanks in advance

dhcp.zip

from python_dhcp_server.

niccokunzmann avatar niccokunzmann commented on June 27, 2024

Thanks for reporting this issue! I think, I assumed this case never to turn up.

Yes to this: #12 (comment)

To me, it seems this is the culprit:

self.queue.put((time.time() + seconds, func, args, kw))

In this line 139, I assume that the times are different or at least that the functions can be ordered (which is possible in Python 2 bu not on Python 3).

If we put an additional item in the list, we would also need to change this line:

t, func, args, kw = p

My solution would be to add a number there which is unique and increased inside a lock, so that there is no multi-threading issue.

_id_lock = threading.Lock()
_id = 0
def get_id():
    global _id
    with _id_lock:
        _id += 1
        return _id

As as an answer to #12 (comment), @greggzj if you create a pull request, we can talk about this and even download the source code of it as a zip file and see the change. I do not know what you did and what the change is and this makes it harder for me, in case this is the accepted solution, to add the change into the source code here.

@greggzj @waukeerules, how would you like to go on from here?

from python_dhcp_server.

greggzj avatar greggzj commented on June 27, 2024

@niccokunzmann thanks for feedback and sorry for the inconvenience.

I create a pull request #13 and the newly implemented PriorityQueue class

  1. no need to modify this line for the self implement priorityqueue class always return item itself exclude the priority identifier index:
    t, func, args, kw = p
  2. Timestamp value is still used as before.

Seems your solution also works. Which one do u prefer ?

from python_dhcp_server.

waukeerules avatar waukeerules commented on June 27, 2024

Thanks for looking into this issue. I was able to create a simple workaround by changing the queuing method to -first in, first out:

self.queue = queue.Queue()

from python_dhcp_server.

niccokunzmann avatar niccokunzmann commented on June 27, 2024

@waukeerules, thanks.... Yep, that is the simplest solution. I used this - the thing is that the packets are re-ordered automatically if it is a queue. So, that is fine and it does not need to be a priority queue.
I am closing this. If anyone finds out that this re-appears, please let me know.

d0d50df

from python_dhcp_server.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.