Opened 3 years ago

Last modified 2 years ago

#8113 enhancement new

MemoryReactor does not provide the interface IReactorCore

Reported by: Reuben Owned by: Reuben
Priority: normal Milestone:
Component: core Keywords:
Cc: Branch:
Author:

Description

from twisted.internet.defer import Deferred
from twisted.internet.fdesc import readFromFD, setNonBlocking
from twisted.internet.task import react
from twisted.test.proto_helpers import MemoryReactor

reactor = MemoryReactor()


def asyncFunc(reactor, filename):
    with open(filename) as f:
        d = Deferred()
        fd = f.fileno()
        setNonBlocking(fd)
        readFromFD(fd, d.callback)
        return d

react(run, ['hello.txt'], reactor)

This throws

AttributeError; 'MemoryReactor' object has no attribute 'addSystemEventTrigger' 

http://stackoverflow.com/q/33730754/408556

Attachments (1)

memory-reactory-interface.patch (3.6 KB) - added by Reuben 3 years ago.
Adds IReactorCore interface to MemoryReactor

Download all attachments as: .zip

Change History (5)

comment:1 Changed 3 years ago by Reuben

Owner: set to Reuben
Type: enhancementdefect

Changed 3 years ago by Reuben

Adds IReactorCore interface to MemoryReactor

comment:2 Changed 3 years ago by Reuben

http://stackoverflow.com/a/33747251/408556

This patch is an implementation of IReactorCore to MemoryReactor so that the example works as desired.

Last edited 3 years ago by Reuben (previous) (diff)

comment:3 Changed 2 years ago by hodgestar

I think we need slightly better implementations of all of the IReactorCore methods. We could start by looking at https://github.com/twisted/twisted/blob/trunk/src/twisted/internet/base.py#L562 and writing implementations inspired by those in the base reactor.

Comments on specific methods:

  • run, stop, crash: these can be copies of the base reactor implementations.
  • resolve: this could return the correct answer for IP addresses and raise a not implemented exception for domain names.
  • fireSystemEvent, addSystemEventTrigger, removeSystemEventTrigger, callWhenRunning: these can be copies of the base reactor implementations.
  • iterate: here I think we should just raise a not implemented error.

Having a more useful MemoryReactor for tests would be pretty cool to have.

comment:4 Changed 2 years ago by hodgestar

Type: defectenhancement
Note: See TracTickets for help on using tickets.