From b080ef632bfbb6b5a2ad35fd6a3cdf0a012dd773 Mon Sep 17 00:00:00 2001 From: Nils Weiss Date: Wed, 15 Jan 2025 08:39:18 +0100 Subject: [PATCH 1/2] Proposal: Set threaded to False in sr1. If the user doesn't specifiy threaded, we should set it to False in sr1 to eliminate the overhead of a thread creation --- scapy/supersocket.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scapy/supersocket.py b/scapy/supersocket.py index 592c581d41f..599ca6131f0 100644 --- a/scapy/supersocket.py +++ b/scapy/supersocket.py @@ -250,6 +250,10 @@ def sr1(self, *args, **kargs): """Send one packet and receive one answer """ from scapy import sendrecv + # if not explicitly specified by the user, + # set threaded to False in sr1 to remove the overhead + # for a Thread creation + kargs["threaded"] = kargs.get("threaded", False) ans = sendrecv.sndrcv(self, *args, **kargs)[0] # type: SndRcvList if len(ans) > 0: pkt = ans[0][1] # type: Packet From 9e91011748b3ea3d55d80e0c63ab9e9ed915cd16 Mon Sep 17 00:00:00 2001 From: Nils Weiss Date: Fri, 31 Jan 2025 08:03:45 +0100 Subject: [PATCH 2/2] Apply feedback --- scapy/supersocket.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scapy/supersocket.py b/scapy/supersocket.py index 599ca6131f0..9744fd841bf 100644 --- a/scapy/supersocket.py +++ b/scapy/supersocket.py @@ -253,7 +253,7 @@ def sr1(self, *args, **kargs): # if not explicitly specified by the user, # set threaded to False in sr1 to remove the overhead # for a Thread creation - kargs["threaded"] = kargs.get("threaded", False) + kargs.setdefault("threaded", False) ans = sendrecv.sndrcv(self, *args, **kargs)[0] # type: SndRcvList if len(ans) > 0: pkt = ans[0][1] # type: Packet