Skip to content

it won't get the right result when use multithread to ping #1

Open

Description

@kwanhur

make a flag in the header packet and then received data by select.select, we can judge the data whether it's the right one.

Activity

  1. roeften commented on Jun 24, 2016

    @roeften

    The issue is that the reply code is not checked, success is reported on any reply

    a start would be to actually check the code:

    index 7592db0..2f09a79 100644
    --- a/gping.py
    +++ b/gping.py
    @@ -204,7 +204,12 @@ class GPing:
                     self.pings[packet_id]['delay'] = time_received - time_sent
    
                     # i'd call that a success
    -                self.pings[packet_id]['success'] = True
    +                if code == 0:
    +                    self.pings[packet_id]['success'] = True
    +                else
    +                    self.pings[packet_id]['success'] = False
    +
    +                self.pings[packet_id]['code'] = code
    
                     # call our callback if we've got one
                     self.pings[packet_id]['callback'](self.pings[packet_id])
    

    patch.txt

  2. kyan001 commented on Jul 7, 2016

    @kyan001

    I met this problem too.

    The reason that this happened is "os.getpid()" returns the same number while multithreading.
    os.getpid() returns different number while multiprocessing.

    the way to solve this is replace "my_ID = os.getpid() & 0xFFFF" by "my_ID = threading.current_thread().ident & 0xFFFF"(py3) in do_one() function.

    I'll fix this in ping3.py and ask for a merge.
    before the pull request works, see my branch @ https://github.com/kyan001/python-ping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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