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

ping3 multiprocessing buggy #23

Closed
joelfranco opened this issue May 8, 2020 · 4 comments
Closed

ping3 multiprocessing buggy #23

joelfranco opened this issue May 8, 2020 · 4 comments

Comments

@joelfranco
Copy link

Hello,
I think that ping3 is buggy when used with multiprocess Process with start method "fork".
Look the code and result:

def doping2(host):
    while True:
        delay = ping3.ping(host)
        import time; time.sleep(1)
        print(host, delay)

if __name__ == "__main__":
    p = argparse.ArgumentParser()
    args = p.parse_args()

    #mp.set_start_method('spawn')

    hosts = ['a.dns.br', 'b.dns.br']
    for i in hosts:
        p = mp.Process(target=doping2, args=(i,))
        p.start()

Result in buggy result (the hosts do not have similar delay times):

root@fat-x220-c577d2:/usr/local/bin# ping123
b.dns.br 0.051039695739746094
a.dns.br 0.05103778839111328
b.dns.br None
a.dns.br None
b.dns.br 0.054898738861083984
a.dns.br 0.054898738861083984
a.dns.br 0.05213785171508789
b.dns.br 0.05213785171508789

But if i insert:
mp.set_start_method('spawn')

it runs fine (actually a.dns.br is blocked):

root@fat-x220-c577d2:/usr/local/bin# ping123
b.dns.br 0.051796674728393555
b.dns.br 0.05194592475891113
b.dns.br 0.05153298377990723
b.dns.br 0.05203509330749512
a.dns.br None
b.dns.br 0.05774235725402832
b.dns.br 0.0719301700592041
b.dns.br 0.06660127639770508
b.dns.br 0.06898736953735352
b.dns.br 0.05692934989929199
a.dns.br None

Is it a bug or an expected result?

Thanks :-)
joel

@kyan001
Copy link
Owner

kyan001 commented May 9, 2020

Hi @joelfranco

After investigation, this one is a bug. When using multiprocessing module, threading.currentThread().ident will retrive the same thread_id, thus they have identical ICMP_ID which makes they are hard to distinguish from each other.

I will make sure that they don't have the same ICMP_ID when being started by either multiprocess or multithread.

Sorry for the inconvience, and thank you for the feedback.

@joelfranco
Copy link
Author

i closed it by mistake. Thank you

@joelfranco joelfranco reopened this May 9, 2020
kyan001 added a commit that referenced this issue May 9, 2020
@kyan001
Copy link
Owner

kyan001 commented May 9, 2020

Hi @joelfranco

I just updated ping3 to 2.6.2. Hopefully it will fix the bug.
Can you give it a try and tell me if it works?
Upgrade: python3 -m pip install -U ping3 or pip3 install -U ping3

Thanks

@joelfranco
Copy link
Author

joelfranco commented May 11, 2020 via email

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

2 participants