The current state of the vortex reactor

Sorry for the vague name, but I could not understand something better.

Is there a way to get the current state of the reactor in a twisted state? By status I mean:

  • Port listeners
  • Connected Protocols
  • Deferrals awaiting dismissal.
  • LoopingCalls that work
  • Topics that are “idle”
  • and other "active" things ...

Basically, I'm trying to figure out if the reactor is just sitting. The question itself is wider than what I really have to do for the sake of completeness for stackoverflow.

Now my current situation is as follows:

I am using someone else's script that listens on many of the “dynamic” ports selected by this person script, so I cannot just use my script to execute something like listenTCP or TCP4ServerEndpoint and check its status. This is somewhat similar to FTP, other than PASV, where each listening port is dropped after each use. Another problem is that my small program also works in the same process that I use as an argument to run its program. This is basically an interface to his program. When all his affairs are completed and my affairs are completed, I want to turn off the reactor. Thus, I am trying to figure out when I can stop the reactor. My exact stop condition:

  • Only listening on one port and the other not.
  • No defaults and cycles that will trigger.

I searched, but found things like "if reactor.running" or stopping a twisted reactor under conditions that needed to be tracked using flags. I would not touch his code. If this is something that can affect the perversion, I would rather do it. But if there is already an alternative, I would prefer not to reinvent the wheel.

Does it need to change its script so that it notifies my script about these conditions?

+6
source share
1 answer

The code you invoke must be reorganized to return Deferred from something; probably the implementation of IService.stopService that stops it. The reason for this is that you do not always know what will sit in the reactor, even when things seem to be “idle”. For example, did you know that Twisted supports a file descriptor ("waker") for communicating with streams? Does the HTTP server constantly keep the callLater outstanding for recording the next entry in the access log? Other parts of the infrastructure in third-party libraries may leave an arbitrary different state in the reactor, which is not really your business.

There is little introspective support in the reactor. For example, there are IReactorTime.getDelayedCalls , IReactorFDSet.getReaders/getWriters , and IReactorThreads.getThreadPool . However, there is no IReactorWin32Events.getAllEvents , so this is not a fully portable set of things. We would definitely appreciate it if you would like to contribute to more complex implementations of introspection of reactors for debugging and diagnostic purposes.

+2
source

Source: https://habr.com/ru/post/922007/


All Articles