Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kwanhur opened this issue Nov 19, 2013 · 2 comments
Open

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

kwanhur opened this issue Nov 19, 2013 · 2 comments

Comments

@kwanhur
Copy link

kwanhur commented Nov 19, 2013

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.

@roeften
Copy link

roeften commented Jun 24, 2016

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

@kyan001
Copy link

kyan001 commented Jul 7, 2016

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants