Code Monkey home page Code Monkey logo

qt5reactor's Introduction

Twisted

gitter_ rtd_ pypi_ ci_

For information on changes in this release, see the NEWS file.

What is this?

Twisted is an event-based framework for internet applications, supporting Python 3.6+. It includes modules for many different purposes, including the following:

  • twisted.web: HTTP clients and servers, HTML templating, and a WSGI server
  • twisted.conch: SSHv2 and Telnet clients and servers and terminal emulators
  • twisted.words: Clients and servers for IRC, XMPP, and other IM protocols
  • twisted.mail: IMAPv4, POP3, SMTP clients and servers
  • twisted.positioning: Tools for communicating with NMEA-compatible GPS receivers
  • twisted.names: DNS client and tools for making your own DNS servers
  • twisted.trial: A unit testing framework that integrates well with Twisted-based code.

Twisted supports all major system event loops -- select (all platforms), poll (most POSIX platforms), epoll (Linux), kqueue (FreeBSD, macOS), IOCP (Windows), and various GUI event loops (GTK+2/3, Qt, wxWidgets). Third-party reactors can plug into Twisted, and provide support for additional event loops.

Installing

To install the latest version of Twisted using pip:

$ pip install twisted

Additional instructions for installing this software are in the installation instructions.

Documentation and Support

Twisted's documentation is available from the Twisted Matrix website. This documentation contains how-tos, code examples, and an API reference.

Help is also available on the Twisted mailing list.

There is also an IRC channel, #twisted, on the Libera.Chat network. A web client is available at web.libera.chat.

Unit Tests

Twisted has a comprehensive test suite, which can be run by tox:

$ tox -l                       # to view all test environments
$ tox -e nocov                 # to run all the tests without coverage
$ tox -e withcov               # to run all the tests with coverage
$ tox -e alldeps-withcov-posix # install all dependencies, run tests with coverage on POSIX platform

You can test running the test suite under the different reactors with the TWISTED_REACTOR environment variable:

$ env TWISTED_REACTOR=epoll tox -e alldeps-withcov-posix

Some of these tests may fail if you:

  • don't have the dependencies required for a particular subsystem installed,
  • have a firewall blocking some ports (or things like Multicast, which Linux NAT has shown itself to do), or
  • run them as root.

Static Code Checkers

You can ensure that code complies to Twisted coding standards:

$ tox -e lint   # run pre-commit to check coding stanards
$ tox -e mypy   # run MyPy static type checker to check for type errors

Or, for speed, use pre-commit directly:

$ pipx run pre-commit run

All of the code in this distribution is Copyright (c) 2001-2024 Twisted Matrix Laboratories.

Twisted is made available under the MIT license. The included LICENSE file describes this in detail.

Warranty

THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE USE OF THIS SOFTWARE IS WITH YOU.

IN NO EVENT WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY, BE LIABLE TO YOU FOR ANY DAMAGES, EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

Again, see the included LICENSE file for specific legal details.

qt5reactor's People

Contributors

altendky avatar bakbuk avatar crwood avatar dependabot[bot] avatar estan avatar exarkun avatar meejah avatar nehbit avatar sibiryakov avatar sunu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

qt5reactor's Issues

QtReactor.run() ignores installSignalHandlers

https://github.com/sunu/qt5reactor/blob/52fe755c0e340718825cdfe495e5308d325ef019/src/qt5reactor/core.py#L309-L322

It's been this way since 2015. (does this qualify as 'forever'?) 505b0c4#diff-b467afb1a9eee3fc0acb458db641fce8R323 but just glancing at it it seems like self.runReturn() should be self.runReturn(installSignalHandlers=installSignalHandlers)?

I haven't looked into it at all, just noticed it while debugging some weird SIGABRT with some new https://github.com/pytest-dev/pytest-twisted changes.

qt5reactor crashes when used with twisted.internet.serialport.SerialPort

I am making a serial port monitor with PyQT5 and Twisted on Windows and have encounted presumably a QT5 internal error. This is the code:

import sys
from PyQt5.QtWidgets import QApplication, QWidget
app = QApplication(sys.argv)
import qt5reactor
qt5reactor.install()

from twisted.internet import reactor
from twisted.protocols.basic import LineReceiver
from twisted.internet.serialport import SerialPort


class Myform(QWidget):
    def __init__(self):
        super().__init__()
        self.setGeometry(10, 10, 100, 100)
        self.show()


class Prot(LineReceiver):
    def rawDataReceived(self, data):
        pass

    def lineReceived(self, line):
        pass


s = SerialPort(Prot(), "com3", reactor, baudrate=57600)
ex = Myform()
reactor.run()

This gives the following error

Process finished with exit code -1073740791 (0xC0000409)

If the SerialPort initialization string is commented, everything works perfectly (the window appears). Otherwize if qt5reactor.install() is commented the twisted code works normally but QT app (obviously) isn't started.

Versioning tools

@sunu wrote:

This is mostly a side note than a review. I'm curious what do you think about using something like bumpversion to manage versioning instead of versioneer. I'm slightly uncomfortable with how we are including large chunks of unrelated code that mostly deals with versioning with the actual source code.

Dependency on pypiwin32?

It might be worth making an explicit dependency on pypiwin32 in setup.py for Windows installs.

Self-interrupting code: QtReactor.doIteration() calling processEvents()

I started with my first Twisted code in a standalone script though still using PyQt5 due to some of my leveraged code for CANbus interfacing. This went quite well but when I started to integrate it back into my application I ran into trouble after adding feedback from 'the twisted code' to a QProgressDialog. It didn't matter if I used a signal/slot or called directly to QProgressDialog.setValue(), I would quickly get my code interrupted (within the same thread) resulting in receiving a network response (coming in via a signal/slot connection) before I finished the post-send code.

While the python-can library underlying my CANbus communication does use a thread from which it provides incoming messages, I have all of those routed through signals/slots to hop the thread boundary safely. I also double checked and the code that was seemingly interrupted and the supposed interrupting code both report the same threading.get_ident(). This suggests to me that it isn't a threading issue (though... I'm not ruling it out. :] ).

See my (to be linked) commit that alleviates this. I will also link my code once I have the exact revision pushed.

Flaky builds around PyQt5/PySide pip downloads

pip and PyPI are having a hard time together on PyQt5 and PySide2 wheels. The packages download incompletely and then fail hash checks. 1) Why are the downloads stopping short? 2) Why is pip failing that out on the hash instead of the incomplete download?

https://github.com/twisted/qt5reactor/runs/934639858?check_suite_focus=true
https://github.com/twisted/qt5reactor/runs/930744031?check_suite_focus=true

ERROR: THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE. If you have updated the package versions, please update the hashes. Otherwise, examine the package contents carefully; someone may have tampered with them.
    pyside2==5.15.0 from https://files.pythonhosted.org/packages/24/39/348e72c1607ac12915e1809e9092e09aa239bc48ace41d51253179e635bb/PySide2-5.15.0-5.15.0-cp35.cp36.cp37.cp38-abi3-manylinux1_x86_64.whl#sha256=f9099e49fb2d3571f5a81eb9ff281ce832ce8c333052e8175e2356b9c3e4a882:
        Expected sha256 f9099e49fb2d3571f5a81eb9ff281ce832ce8c333052e8175e2356b9c3e4a882
             Got        43a032f3b7b72f1e0139ac9c4d798ec4a947a7343f014bb70714f266b5d75a21

Reported:

Other resolutions:

qt5reactor increases idle CPU usage

I recently noticed that applications using qt5reactor will continuously consume additional CPU time when idle (a steady 2-3% on My Machine) -- a behavior that is not seen/observed in competing solutions (e.g., using quamash with asyncio or even running Twisted's reactor in a separate thread from the Qt event loop and communicating between the two using Qt signals/slots). Has anybody else noticed the same and/or done any prior investigating in relation to this? I'm not as familiar with Twisted's internals as I should be but I would like to try to fix/reduce this if possible (and figured I should at least open an issue here to invite further discussion/collaboration before delving into it further).

Should we move this repo to an organization?

@sunu, @crwood, what do you think about moving this project to an organization? I'm concerned by the low activity from all of us for extended times. Sure, the code works but if we drift away then having it in an organization would make it more readily handed on to any successors. Also, it would put more people as admin for the GitHub side of things. I checked and @glyph was willing to consider it for inclusion in the Twisted organization (I didn't ask about the core repo, just the org).

To be open and complete, I might be drifting towards trio so I can't make promises that I'll be a long term maintainer. I'm only in preliminary stages of exploring how to build up the Qt and pytest integration after they recently implemented their guest mode. Even if that all pans out I still have a pile of code for work that would need to be rewritten before I was no longer using Twisted/qt5reactor. Still, I figure it's good for all to be aware as part of this discussion.

(FYI @exarkun, @meejah)

  • Pick Twisted vs. dedicated org
    • Twisted it is
  • Decide if we are going to change names
    • Maybe later
  • Change names if we decided to
  • Give @sunu acccess to org
  • Move repository to org
  • Add existing maintainers in new org
  • Add new Twisted maintainers to PyPI
  • Update all links (I think just in-repo plus release to PyPI after?)
  • Shutdown existing CI
  • Setup new CI (at least GitHub 'all' job as required)
  • New release to get PyPI link updated (probably wait until the PRs are resolved)

Please update the pypi version

I am creating a snap that uses this reactor, it would be very convenient if the latest version was available from pypi.

Please push the latest to pypi :-)

Recursion depth exceeded exception

2016-04-18 22:44:46-0700 [WProtocol,0,192.168.1.202] Unhandled Error
    Traceback (most recent call last):
      File "/Users/j/SOURCE/w/qt5reactor.py", line 305, in doIteration
        self.qApp.processEvents(QEventLoop.AllEvents, delay * 1000)
      File "/Users/j/SOURCE/w/qt5reactor.py", line 291, in _iterate
        self.doIteration(delay, fromqt)
      File "/Users/j/SOURCE/w/qt5reactor.py", line 305, in doIteration
        self.qApp.processEvents(QEventLoop.AllEvents, delay * 1000)
      File "/Users/j/SOURCE/w/qt5reactor.py", line 186, in write
        log.callWithLogger(w, _write)
    --- <exception caught here> ---
      File "/Users/j/.virtualenvs/w/lib/python2.7/site-packages/twisted/python/log.py", line 101, in callWithLogger
        return callWithContext({"system": lp}, func, *args, **kw)
      File "/Users/j/.virtualenvs/w/lib/python2.7/site-packages/twisted/python/log.py", line 84, in callWithContext
        return context.call({ILogContext: newCtx}, func, *args, **kw)
      File "/Users/j/.virtualenvs/w/lib/python2.7/site-packages/twisted/python/context.py", line 118, in callWithContext
        return self.currentContext().callWithContext(ctx, func, *args, **kw)
      File "/Users/j/.virtualenvs/w/lib/python2.7/site-packages/twisted/python/context.py", line 81, in callWithContext
        return func(*args,**kw)
      File "/Users/j/SOURCE/w/qt5reactor.py", line 185, in _write
        self.reactor._iterate(fromqt=True)
      File "/Users/j/SOURCE/w/qt5reactor.py", line 290, in _iterate
        self.runUntilCurrent()
      File "/Users/j/.virtualenvs/w/lib/python2.7/site-packages/twisted/internet/base.py", line 827, in runUntilCurrent
        log.deferr()
      File "/Users/j/.virtualenvs/w/lib/python2.7/site-packages/twisted/python/log.py", line 132, in err
        msg(failure=_stuff, why=_why, isError=1, **kw)
      File "/Users/j/.virtualenvs/w/lib/python2.7/site-packages/twisted/python/threadable.py", line 53, in sync
        return function(self, *args, **kwargs)
      File "/Users/j/.virtualenvs/w/lib/python2.7/site-packages/twisted/python/log.py", line 282, in msg
        _publishNew(self._publishPublisher, actualEventDict, textFromEventDict)
      File "/Users/j/.virtualenvs/w/lib/python2.7/site-packages/twisted/logger/_legacy.py", line 154, in publishToNewObserver
        observer(eventDict)
      File "/Users/j/.virtualenvs/w/lib/python2.7/site-packages/twisted/logger/_observer.py", line 136, in __call__
        errorLogger = self._errorLoggerForObserver(brokenObserver)
      File "/Users/j/.virtualenvs/w/lib/python2.7/site-packages/twisted/logger/_observer.py", line 156, in _errorLoggerForObserver
        if obs is not observer
      File "/Users/j/.virtualenvs/w/lib/python2.7/site-packages/twisted/logger/_observer.py", line 81, in __init__
        self.log = Logger(observer=self)
      File "/Users/j/.virtualenvs/w/lib/python2.7/site-packages/twisted/logger/_logger.py", line 52, in __init__
        namespace = self._namespaceFromCallingContext()
      File "/Users/j/.virtualenvs/w/lib/python2.7/site-packages/twisted/logger/_logger.py", line 32, in _namespaceFromCallingContext
        return currentframe(2).f_globals["__name__"]
    exceptions.RuntimeError: maximum recursion depth exceeded

2016-04-18 22:44:46-0700 [WProtocol,0,192.168.1.202] Unhandled Error
    Traceback (most recent call last):
      File "/Users/j/SOURCE/w/qt5reactor.py", line 305, in doIteration
        self.qApp.processEvents(QEventLoop.AllEvents, delay * 1000)
      File "/Users/j/SOURCE/w/qt5reactor.py", line 291, in _iterate
        self.doIteration(delay, fromqt)
      File "/Users/j/SOURCE/w/qt5reactor.py", line 305, in doIteration
        self.qApp.processEvents(QEventLoop.AllEvents, delay * 1000)
      File "/Users/j/SOURCE/w/qt5reactor.py", line 165, in read
        log.callWithLogger(w, _read)
    --- <exception caught here> ---
      File "/Users/j/.virtualenvs/w/lib/python2.7/site-packages/twisted/python/log.py", line 101, in callWithLogger
        return callWithContext({"system": lp}, func, *args, **kw)
      File "/Users/j/.virtualenvs/w/lib/python2.7/site-packages/twisted/python/log.py", line 84, in callWithContext
        return context.call({ILogContext: newCtx}, func, *args, **kw)
      File "/Users/j/.virtualenvs/w/lib/python2.7/site-packages/twisted/python/context.py", line 118, in callWithContext
        return self.currentContext().callWithContext(ctx, func, *args, **kw)
      File "/Users/j/.virtualenvs/w/lib/python2.7/site-packages/twisted/python/context.py", line 81, in callWithContext
        return func(*args,**kw)
      File "/Users/j/SOURCE/w/qt5reactor.py", line 157, in _read
        log.err()
      File "/Users/j/.virtualenvs/w/lib/python2.7/site-packages/twisted/python/log.py", line 132, in err
        msg(failure=_stuff, why=_why, isError=1, **kw)
      File "/Users/j/.virtualenvs/w/lib/python2.7/site-packages/twisted/python/threadable.py", line 53, in sync
        return function(self, *args, **kwargs)
      File "/Users/j/.virtualenvs/w/lib/python2.7/site-packages/twisted/python/log.py", line 282, in msg
        _publishNew(self._publishPublisher, actualEventDict, textFromEventDict)
      File "/Users/j/.virtualenvs/w/lib/python2.7/site-packages/twisted/logger/_legacy.py", line 154, in publishToNewObserver
        observer(eventDict)
      File "/Users/j/.virtualenvs/w/lib/python2.7/site-packages/twisted/logger/_observer.py", line 136, in __call__
        errorLogger = self._errorLoggerForObserver(brokenObserver)
      File "/Users/j/.virtualenvs/w/lib/python2.7/site-packages/twisted/logger/_observer.py", line 156, in _errorLoggerForObserver
        if obs is not observer
      File "/Users/j/.virtualenvs/w/lib/python2.7/site-packages/twisted/logger/_observer.py", line 81, in __init__
        self.log = Logger(observer=self)
    exceptions.RuntimeError: maximum recursion depth exceeded

^C2016-04-18 22:44:48-0700 [-] Received SIGINT, shutting down.
2016-04-18 22:44:48-0700 [twisted.internet.protocol.Factory] (TCP Port 4337 Closed)
2016-04-18 22:44:48-0700 [-] Stopping factory <twisted.internet.protocol.Factory instance at 0x10da9bfc8>

This recursion exception is thrown while chunking a large file and sending 16k blocks as messages through AMP. It happens very erratically. I'll try to put together some test code that exposes it. May be difficult since it seems to be so unpredictable.

using Twisted 16.1.1 , Python 2.7.11 , PyQt 5.5.1

`QtEventReactor.timeout()`: `unorderable types: float() < NoneType()`

I sometimes get:

<class 'TypeError'>: 
unorderable types: float() < NoneType()
----------------------------------------------------------------------
  File "c:\users\ieuser\desktop\src\st\venv\src\qt5reactor\qt5reactor.py", line 411, in iterate
    self.doIteration(delay, fromqt=True)
  File "c:\users\ieuser\desktop\src\st\venv\src\qt5reactor\qt5reactor.py", line 308, in doIteration
    if self.timeout() is None:
  File "c:\users\ieuser\desktop\src\st\venv\src\qt5reactor\qt5reactor.py", line 402, in timeout
    return min(t, 0.01)

See my (to be linked) commit that alleviates this.

Of course, if you think something else is wrong and another solution should be found I'll work on that. I'll share an exact commit from https://github.com/altendky/st once I have it pushed.

Cannot find the qt5 reactor for trial

I am trying to trial the reactor on macOS 10.12.6, I installed python 2.7 and twisted via homebrew, and qt5reactor via pip2. Although qt5reactor is correctly installed and importable on python2, I could not manage to run the trial tests. Trial is not able to find the reactor (The specified reactor does not exist: 'qt5'.). I am convinced this is entirely a path issue, however, I tried to run the trial command from /usr/local/lib/python2.7/site-packages/, which is the folder that contains the qt5reactor.py file, but I still get the same error message. The README says to check that the "plugin directory" is in the path or is the current directory, but I do not quite understand which one it is. Thanks for your help.

Tests pass but process doesn't terminate

When running with v0.5 my tests pass but the process won't end. With fcc4186 (@exarkun) reverted they pass and the process ends.

Builds passing: https://travis-ci.org/altendky/altendpyqt5/builds/427012146
My 'fixed' branch: ce3ea2d

https://gist.github.com/altendky/15cc377d88ae3635a1597fba770ed9f0

 ~/altendpyqt5   6-signal_deferred ●  git rev-parse HEAD
47ea0b23dea0e82fca11f66265e679c86f872e14
 ~/altendpyqt5   6-signal_deferred ●  gd requirements.test
diff --git a/requirements.test b/requirements.test
index 6612d83..644a196 100644
--- a/requirements.test
+++ b/requirements.test
@@ -25,7 +25,7 @@ pytest-qt==3.0.2
 pytest-twisted==1.8
 pytest-xvfb==1.1.0
 PyVirtualDisplay==0.2.1
-git+https://github.com/altendky/qt5reactor@a52c0d0c289c8e08680c0204974081c541504d41#egg=qt5reactor
+qt5reactor
 requests==2.19.1
 six==1.11.0
 tox==3.2.1
 ~/altendpyqt5   6-signal_deferred ●  venv/bin/pytest -vvvvvvvv -s altendpyqt5.tests --reactor=qt5reactor -m twisted --pyargs
================================================================================ test session starts =================================================================================
platform linux -- Python 3.6.6, pytest-3.7.4, py-1.6.0, pluggy-0.7.1 -- /home/altendky/altendpyqt5/venv/bin/python3.6
cachedir: .pytest_cache
PyQt5 5.11.2 -- Qt runtime 5.11.1 -- Qt compiled 5.11.1
rootdir: /home/altendky/altendpyqt5, inifile:
plugins: xvfb-1.1.0, twisted-1.8, qt-3.0.2, cov-2.5.1, asyncio-0.9.0
collected 18 items / 14 deselected                                                                                                                                                   

src/altendpyqt5/tests/test_twisted.py::test_yield_for_signal PASSED
src/altendpyqt5/tests/test_twisted.py::test_yield_for_signal_arguments PASSED
src/altendpyqt5/tests/test_twisted.py::test_await_for_signal PASSED
src/altendpyqt5/tests/test_twisted.py::test_await_for_signal_result PASSED^CUnhandled Error
Traceback (most recent call last):
  File "/home/altendky/altendpyqt5/venv/lib/python3.6/site-packages/twisted/python/context.py", line 122, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/home/altendky/altendpyqt5/venv/lib/python3.6/site-packages/twisted/python/context.py", line 85, in callWithContext
    return func(*args,**kw)
  File "/home/altendky/altendpyqt5/venv/lib/python3.6/site-packages/qt5reactor.py", line 165, in _read
    self.reactor._iterate(fromqt=True)
  File "/home/altendky/altendpyqt5/venv/lib/python3.6/site-packages/qt5reactor.py", line 271, in _iterate
    self.runUntilCurrent()
--- <exception caught here> ---
  File "/home/altendky/altendpyqt5/venv/lib/python3.6/site-packages/twisted/internet/base.py", line 869, in runUntilCurrent
    f(*a, **kw)
  File "/home/altendky/altendpyqt5/venv/lib/python3.6/site-packages/twisted/internet/base.py", line 630, in stop
    "Can't stop reactor that isn't running.")
twisted.internet.error.ReactorNotRunning: Can't stop reactor that isn't running.



====================================================================== 4 passed, 14 deselected in 7.73 seconds =======================================================================

What is the proper way to launch the qt5reactor and QApplication?

I started using threads and ran into some issues. Turns out that while the reactor was 'working' for many things it wasn't getting started correctly and so deferToThread() didn't work and even when I started it up the application would then hang on exit.

What is the proper way to launch the qt5reactor and QApplication?

The readme covers installing the reactor in one of two ways but does not cover reactor.run() vs app.exec() or maybe something with reactor.runReturn() or...

My simple example for deferToThread() (both for qt5reactor and pure twisted) are available in this gist.

https://gist.github.com/altendky/faf48446c335418dac8793635d119750

DeprecationWarning: reactor.iterate cannot be used inside unit tests. In the future, using iterate will fail the test and may crash or hang the test run.

https://github.com/pytest-dev/pytest-twisted/pull/94/checks?check_run_id=692810777

============================= test session starts ==============================
platform linux -- Python 3.6.10, pytest-5.4.2, py-1.8.1, pluggy-0.13.1 -- /__w/pytest-twisted/pytest-twisted/.tox/py36-qt5reactor/bin/python
cachedir: .pytest_cache
PyQt5 5.14.2 -- Qt runtime 5.14.2 -- Qt compiled 5.14.2
rootdir: /tmp/pytest-of-root/pytest-0/test_scrapy____something0
plugins: qt-3.3.0, xvfb-1.2.0, twisted-1.12
collecting ... collected 1 item

test_scrapy____something.py::Test::test PASSED                           [100%]

=============================== warnings summary ===============================
test_scrapy____something.py::Test::test
  /__w/pytest-twisted/pytest-twisted/.tox/py36-qt5reactor/lib/python3.6/site-packages/qt5reactor/core.py:292: DeprecationWarning: reactor.iterate cannot be used inside unit tests. In the future, using iterate will fail the test and may crash or hang the test run.
    self.iterate(delay=delay, fromqt=True)

-- Docs: https://docs.pytest.org/en/latest/warnings.html
========================= 1 passed, 1 warning in 0.10s =========================

https://github.com/sunu/qt5reactor/blob/8aaf354ef5d5ec07aca4fbe3c4ec9fba2c476ee9/src/qt5reactor/core.py#L291-L292

pytest tests with qt5reactor?

I've worked with pytest-qt and pytest-twisted but I haven't seen yet a pytest-qt5reactor or similar. Does such a thing exist? Does anyone happen to be expert enough to do it?

I'll be digging on it myself but I have a feeling I've got a good bit to learn.

Better setup for managing pinned deps

Following up on the unresolved WIP items in #24.

Perhaps there is some tooling that can help monitor and maintain our pinned testing deps?

@crwood wrote: #24 (comment)

For what it's worth, some of these version-pins are out of date (off-hand, at least, I know Twisted 18.9.0 has been released, zope.interface 4.6.0 is out now -- there may be more..). If you're committed to pinning specific versions here, would it be worth also looking into using/enabling a service like requires.io or pyup to help update such pins moving forward? (I don't currently use these services myself, but it might ease the burden on current/future maintainers if we're going to be pinning all the things).

Always crashes precisely 60 seconds after reactor.run()

Traceback (most recent call last):
  File "D:\Python35\lib\site-packages\qt5reactor.py", line 402, in iterate
    self.doIteration(delay)
  File "D:\Python35\lib\site-packages\qt5reactor.py", line 308, in doIteration
    if self.timeout() is None:
  File "D:\Python35\lib\site-packages\qt5reactor.py", line 393, in timeout
    return min(t, 0.01)
TypeError: unorderable types: float() < NoneType()

This happens every time, and always 60 seconds after reactor.run() was called.
I'm using Python 3.5.1, Twisted 16.2.0, PyQT 5.6, on Windows 7.

I'm using this code:

from PyQt5.QtWidgets import QApplication
from twisted.internet.protocol import ClientFactory
from twisted.protocols.basic import LineReceiver
import sys

class MyClientProtocol(LineReceiver):
    pass

class MyClientFactory(ClientFactory):
    def buildProtocol(self, addr):
        return MyClientProtocol()

    def startedConnecting(self, connector):
        print('Started connecting..')

app = QApplication(sys.argv)    
import qt5reactor
qt5reactor.install()
from twisted.internet import reactor
reactor.connectTCP('localhost', 8123, MyClientFactory())
reactor.run()
sys.exit(app.exec_())

autobahn wamp call works in onJoin but not in button event

Hi, I am attempting to use qt5reactor in order to do crossbar.io wamp calls from a pyqt5 application. I have it working to the point that I can do a wamp call from the onJoin callback but when I try to put the call in a button event I get an immediate 'TransportLost' exception and the call does not go through.

In the code below, the call in the onJoin callback works but the call in the message_to callback (from a button) does not.

import sys, json
import qt5reactor
from PyQt5.QtWidgets import QApplication, QLabel, QMainWindow, QVBoxLayout, QLineEdit, QPushButton, QListView, QWidget
from PyQt5.QtCore import Qt
from autobahn.twisted.wamp import ApplicationSession
from autobahn.twisted.wamp import ApplicationRunner
from autobahn.wamp import auth
from autobahn.wamp.exception import SessionNotReady
from chatinclude import MessageModel, MessageDelegate

# Subclass QMainWindow to customise your application's main window
from twisted.internet.defer import inlineCallbacks


class MainWindow(QMainWindow, ApplicationSession):

    def __init__(self, *args, **kwargs):
        self.global_authid = "test-chat-client"
        self.global_key = "MYKEY"
        super(MainWindow, self).__init__()
        super(ApplicationSession, self).__init__(*args, **kwargs)
        # Layout the UI
        l = QVBoxLayout()

        self.message_input = QLineEdit("Enter message here")

        # Buttons for from/to messages.
        self.btn1 = QPushButton("<")
        self.btn2 = QPushButton(">")

        self.messages = QListView()
        self.messages.setResizeMode(QListView.Adjust)
        # Use our delegate to draw items in this view.
        self.messages.setItemDelegate(MessageDelegate())

        self.model = MessageModel()
        self.messages.setModel(self.model)

        self.btn1.pressed.connect(self.message_to)
        self.btn2.pressed.connect(self.message_from)

        l.addWidget(self.messages)
        l.addWidget(self.message_input)
        l.addWidget(self.btn1)
        l.addWidget(self.btn2)

        self.w = QWidget()
        self.w.setLayout(l)
        self.setCentralWidget(self.w)

    @inlineCallbacks
    def message_to(self):
        USER_ME=0
        try:
            res2 = yield self.call(u'biz.domain.register_chat')
            print("\nget data result: {}\n".format(res2))
            self.model.add_message(USER_ME, self.message_input.text())
        except Exception as e:
            print("get data call error: {0}".format(e))

    def message_from(self):
        USER_THEM=1
        self.model.add_message(USER_THEM, self.message_input.text())

    def onConnect(self):
        print("CONNECT", self.global_authid)
        self.join(u"unwait", ['wampcra'], self.global_authid)

    def onChallenge(self, challenge):
        print("CHALLENGE",challenge.method)
        if challenge.method == u"wampcra":
            signature = auth.compute_wcs(self.global_key.encode('utf8'),
                                         challenge.extra['challenge'].encode('utf8'))
            return signature.decode('ascii')
        else:
            raise Exception("don't know how to handle authmethod {}".format(challenge.method))
        return None

    @inlineCallbacks
    def onJoin(self, details):
        print("JOIN")
        try:
            res2 = yield self.call(u'biz.domain.register_chat')
            print("\nget data result: {}\n".format(res2))
        except Exception as e:
            print("get data call error: {0}".format(e))

    def onLeave(self, details):
        print("LEAVE")

    def closeEvent(self, event):
        pass


app = QApplication(sys.argv)
qt5reactor.install()
runner = ApplicationRunner(url='ws://IPADDR:9001/ws', realm='myrealm')

window = MainWindow()
window.show()
runner.run(MainWindow)
#app.exec_()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.