How to terminate scapy.sniff on keyboard press? - scapy

As mentioned in the question was wondering what is the best solution to terminate scapy when using infinet loop without setting packet count

Related

How to stop an infinite loop safely in JupyterLab?

We are using jupyterLab for some long running operations (doing physic simulations in our case). The user should be able to stop these operations safely without killing the kernel.
Is there a clean ways to do this?
Are there maybe even best practices for this?
My cell looks something like this:
environment = gym.make()
running = True
while running:
environment.step()
running = ???
serialize(environment)
Notes
This is not a duplicate of How to stop the running cell if interupt kernel does not work[...], because I'm looking for a save way to stop without interrupting the control flow.
This is not a duplicate of How to stop an infinite loop safely in Python?, because I'm looking for a way that is suited for JupyterNotebooks and JupyterLab.
According to https://stackoverflow.com/a/19040553/, IPython interrupts the kernel by sending a SIGINT. Shouldn't it be possible to catch and handle the signal programmatically, as described in How to stop an infinite loop safely in Python?.
Edit: This sounds helpful: graceful interrupt of while loop in ipython notebook

Waiting on dissimilar input channels

I'm trying to write a program that listens on a RabbitMQ queue and display statistics using curses.
I would like to listen for keystrokes (to quit or change the display) and queue messages at the same time, reacting appropriately as soon as they arrive. I might also want to add another dissimilar input down the line, such as a socket.
What is the simplest way to accomplish something like this in Python3? selectors? Threads? asyncio?
There seems to be a plethora of options, and yet, it's never clear to me that any of them will meet my use case.

digitalWrite best practice in Arduino

I have a loop checking the status of a sensor. If it's in one state, I light a LED using digitalWrite (1,HIGH), otherwise, I write LOW. This happens in a tight loop many times a second.
Is it fine to write so many times, or is it better practice to set a flag and only write if the flag has changed?
It shouldn't be a problem for the board. You could also add a short delay at the end of the loop (delay(5);)

Signal generated for closing the window?

I'm using centOs 6.3(Final) version. My question is which signal is generated on pressing the close button for a window? Is the close button equivalent to alt-f4? Or is my whole understanding is wrong and centOs does not use the signal model for it's graphical windows?
If possible please specify the source of the answer since I need to document it.
Thanks
Assuming we are talking about at the X11 level here then the signal you are looking for is likely WM_DELETE_WINDOW or the DestroyRequest/DestroyNotify event.
This has nothing to do (again at the X11 level) with signal(2) or signal(7). Though it is entirely possible that in some circumstances (hung processes or similar) that those signals would be used to terminate the terminal process.
It is also likely that the shell/etc. running inside the terminal are going to receive various signals which terminate their operation.
As said here: You can use wmctrl:
wmctrl -c appName
More aggressive would be to grep the PID to send a POSIX signal like SIGTERM (15, Ctrl-c) (see notes below).
Notes
Very similar to How can I kill a specific X window
You can also try with xdottool

Best way to wait for infiniband receive completions on Linux?

We're porting Isis2 (isis2.codeplex.com) to make better use of Infiniband verbs and have our code running. However, IB is oriented around an asynchronous receive model in which you post a bunch of receive buffers and then, as receives complete, you process the received data.
Polling is slow: if I use a blocking wait for, say, 2ms, I might delay as long as 2ms before seeing the IB data. So that's a solution, but a poor one. What I really want is a way to wait until an IB completion record is finalized and then to have my thread wake up instantly (on Windows this is easy... on Linux it isn't as natural). Does anyone know how one does this? When using Verbs, there isn't any IB file descriptor, so obviously I can't use select()
Never mind; we just realized that they offer a method (ibv_reg_notify_cq) for this. We'll try that. Not the world's best documented API...

Resources