Opened 6 years ago

Last modified 2 months ago

#3413 enhancement new

get twisted to run on jython

Reported by: glyph Owned by:
Priority: normal Milestone:
Component: core Keywords: jython
Cc: thijs, tobias.oberstein@…, tkanerva@…, Arfrever.FTA@… Branch: branches/jython-3413-3
(diff, github, buildbot, log)
Author: thijs, glyph Launchpad Bug:

Description (last modified by thijs)

There are some other tickets which imply this as a goal, but it hasn't been made explicit that this is desired.

This ticket should be closed when we have a jython buildbot that is green.

Related tickets

Attachments (5)

nasty-hacks.diff (2.2 KB) - added by glyph 6 years ago.
Some nasty hacks just so we can see trial start up and report bugs in Jython
signal.py (4.5 KB) - added by glyph 6 years ago.
Accompanying the nasty hacks mentioned above, this is a signal module that provides almost enough stuff to get started
jython-lazyByteSlice.diff (1.0 KB) - added by tkanerva 13 months ago.
use PY3 implementation of lazyByteSlice for jython2.7 as well
jython-abstract_concatenate.diff (836 bytes) - added by tkanerva 13 months ago.
use PY3 code path in t.i.abstract._concatenate to enable jython
jython-threadable.diff (608 bytes) - added by tkanerva 13 months ago.
a workaround for jython thread module to find the thread ID

Download all attachments as: .zip

Change History (47)

comment:1 Changed 6 years ago by glyph

  • Description modified (diff)

Changed 6 years ago by glyph

Some nasty hacks just so we can see trial start up and report bugs in Jython

Changed 6 years ago by glyph

Accompanying the nasty hacks mentioned above, this is a signal module that provides almost enough stuff to get started

comment:2 follow-up: Changed 6 years ago by glyph

Signal module derived from one pasted at http://pylonshq.com/pasties/646 - copying it here because pastebins typically aren't permanent.

comment:3 Changed 6 years ago by thijs

  • Cc thijs added
  • Keywords jython added

comment:5 Changed 6 years ago by vschiavoni

what is the exact steps to locally reproduce the error that is now stopping the buildbot (http://buildbot.twistedmatrix.com/builders/ubuntu64-jython2.5-select/builds/99) ?
That is, which version to checkout ? which build tool can I execute ?

comment:6 follow-up: Changed 6 years ago by vschiavoni

Currently, the build process fails due to a missing dependency toward jruby:

jython -v  setup.py install
import: 'exceptions' as org.python.core.exceptions in builtin modules
import: import site # precompiled from /Users/veleno/jython2.5b1/Lib/site$py.class
import: 'sys' as sys in builtin modules
import: import os # precompiled from /Users/veleno/jython2.5b1/Lib/os$py.class
import: 'errno' as org.python.modules.errno in builtin modules
import: 'jarray' as org.python.modules.jarray in builtin modules
import: 'java' as java package
import: 'System' as java class
import: 'time' as org.python.modules.time.Time in builtin modules
import: import stat # precompiled from /Users/veleno/jython2.5b1/Lib/stat$py.class
import: 'File' as java class
import: 'org' as java package
import: 'FileDescriptors' as java class
import: 'FileIO' as java class
import: 'IOBase' as java class
import: 'Py' as java class
import: 'Errno' as java class
import: 'JavaPOSIX' as java class
import: 'POSIXHandler' as java class
import: 'POSIXFactory' as java class
import: import posixpath # precompiled from /Users/veleno/jython2.5b1/Lib/posixpath$py.class
import: 'IOException' as java class
import: 'SecureRandom' as java class
import: 'FileDescriptor' as java class
import: import twisted # precompiled from ./twisted/__init__$py.class
import: import twisted.python # precompiled from ./twisted/python/__init__$py.class
import: import twisted.python.compat # precompiled from ./twisted/python/compat$py.class
import: import string # precompiled from /Users/veleno/jython2.5b1/Lib/string$py.class
import: import re # precompiled from /Users/veleno/jython2.5b1/Lib/re$py.class
import: import sre_compile # precompiled from /Users/veleno/jython2.5b1/Lib/sre_compile$py.class
import: '_sre' as org.python.modules._sre in builtin modules
import: import sre_constants # precompiled from /Users/veleno/jython2.5b1/Lib/sre_constants$py.class
import: import sre_parse # precompiled from /Users/veleno/jython2.5b1/Lib/sre_parse$py.class
import: import copy_reg # precompiled from /Users/veleno/jython2.5b1/Lib/copy_reg$py.class
import: import types # precompiled from /Users/veleno/jython2.5b1/Lib/types$py.class
import: import socket # precompiled from /Users/veleno/jython2.5b1/Lib/socket$py.class
import: 'struct' as org.python.modules.struct in builtin modules
import: import threading # precompiled from /Users/veleno/jython2.5b1/Lib/threading$py.class
import: 'InterruptedException' as java class
import: 'Collections' as java class
import: 'WeakHashMap' as java class
import: 'Semaphore' as java class
import: 'CyclicBarrier' as java class
import: 'ReentrantLock' as java class
import: 'jython' as java class
import: 'thread' as org.python.modules.thread.thread in builtin modules
import: 'Thread' as java class
import: import weakref # precompiled from /Users/veleno/jython2.5b1/Lib/weakref$py.class
import: import UserDict # precompiled from /Users/veleno/jython2.5b1/Lib/UserDict$py.class
import: '_weakref' as org.python.modules._weakref.WeakrefModule in builtin modules
import: import traceback # precompiled from /Users/veleno/jython2.5b1/Lib/traceback$py.class
import: import linecache # precompiled from /Users/veleno/jython2.5b1/Lib/linecache$py.class
import: import atexit # precompiled from /Users/veleno/jython2.5b1/Lib/atexit$py.class
import: 'BufferedInputStream' as java class
import: 'BufferedOutputStream' as java class
import: 'InterruptedIOException' as java class
import: 'String' as java class
import: 'Exception' as java class
import: 'DatagramPacket' as java class
import: 'InetAddress' as java class
import: 'InetSocketAddress' as java class
import: 'Socket' as java class
import: 'BindException' as java class
import: 'ConnectException' as java class
import: 'NoRouteToHostException' as java class
import: 'PortUnreachableException' as java class
import: 'ProtocolException' as java class
import: 'SocketException' as java class
import: 'SocketTimeoutException' as java class
import: 'UnknownHostException' as java class
import: 'ByteBuffer' as java class
import: 'DatagramChannel' as java class
import: 'ServerSocketChannel' as java class
import: 'SocketChannel' as java class
import: 'AlreadyConnectedException' as java class
import: 'AsynchronousCloseException' as java class
import: 'CancelledKeyException' as java class
import: 'ClosedByInterruptException' as java class
import: 'ClosedChannelException' as java class
import: 'ClosedSelectorException' as java class
import: 'ConnectionPendingException' as java class
import: 'IllegalBlockingModeException' as java class
import: 'IllegalSelectorException' as java class
import: 'NoConnectionPendingException' as java class
import: 'NonReadableChannelException' as java class
import: 'NonWritableChannelException' as java class
import: 'NotYetBoundException' as java class
import: 'NotYetConnectedException' as java class
import: 'UnresolvedAddressException' as java class
import: 'UnsupportedAddressTypeException' as java class
import: 'javax' as java package
import: 'SSLSocketFactory' as java class
import: 'DatagramSocketIO' as java class
import: 'ServerSocketIO' as java class
import: 'SocketIO' as java class
import: 'operator' as org.python.modules.operator in builtin modules
import: import twisted._version # precompiled from ./twisted/_version$py.class
import: import twisted.python.versions # precompiled from ./twisted/python/versions$py.class
import: import twisted.copyright # precompiled from ./twisted/copyright$py.class
import: import twisted.python.dist # precompiled from ./twisted/python/dist$py.class
import: import distutils # precompiled from /Users/veleno/jython2.5b1/Lib/distutils/__init__$py.class
import: import distutils.command # precompiled from /Users/veleno/jython2.5b1/Lib/distutils/command/__init__$py.class
import: import distutils.command.build_scripts # precompiled from /Users/veleno/jython2.5b1/Lib/distutils/command/build_scripts$py.class
import: import distutils.sysconfig # precompiled from /Users/veleno/jython2.5b1/Lib/distutils/sysconfig$py.class
import: import distutils.errors # precompiled from /Users/veleno/jython2.5b1/Lib/distutils/errors$py.class
import: import distutils.core # precompiled from /Users/veleno/jython2.5b1/Lib/distutils/core$py.class
import: import distutils.debug # precompiled from /Users/veleno/jython2.5b1/Lib/distutils/debug$py.class
import: import distutils.util # precompiled from /Users/veleno/jython2.5b1/Lib/distutils/util$py.class
import: import distutils.dep_util # precompiled from /Users/veleno/jython2.5b1/Lib/distutils/dep_util$py.class
import: import distutils.spawn # precompiled from /Users/veleno/jython2.5b1/Lib/distutils/spawn$py.class
import: import distutils.log # precompiled from /Users/veleno/jython2.5b1/Lib/distutils/log$py.class
import: import distutils.dist # precompiled from /Users/veleno/jython2.5b1/Lib/distutils/dist$py.class
import: import copy # precompiled from /Users/veleno/jython2.5b1/Lib/copy$py.class
import: 'PyStringMap' as java class
import: import warnings # precompiled from /Users/veleno/jython2.5b1/Lib/warnings$py.class
import: import distutils.fancy_getopt # precompiled from /Users/veleno/jython2.5b1/Lib/distutils/fancy_getopt$py.class
import: import getopt # precompiled from /Users/veleno/jython2.5b1/Lib/getopt$py.class
import: import distutils.cmd # precompiled from /Users/veleno/jython2.5b1/Lib/distutils/cmd$py.class
import: import distutils.dir_util # precompiled from /Users/veleno/jython2.5b1/Lib/distutils/dir_util$py.class
import: import distutils.file_util # precompiled from /Users/veleno/jython2.5b1/Lib/distutils/file_util$py.class
import: import distutils.archive_util # precompiled from /Users/veleno/jython2.5b1/Lib/distutils/archive_util$py.class
import: import distutils.extension # precompiled from /Users/veleno/jython2.5b1/Lib/distutils/extension$py.class
import: import distutils.command.install_data # precompiled from /Users/veleno/jython2.5b1/Lib/distutils/command/install_data$py.class
import: import distutils.command.build_ext # precompiled from /Users/veleno/jython2.5b1/Lib/distutils/command/build_ext$py.class
import: import distutils.command.build_py # precompiled from /Users/veleno/jython2.5b1/Lib/distutils/command/build_py$py.class
import: import glob # precompiled from /Users/veleno/jython2.5b1/Lib/glob$py.class
import: import fnmatch # precompiled from /Users/veleno/jython2.5b1/Lib/fnmatch$py.class
import: import ConfigParser # precompiled from /Users/veleno/jython2.5b1/Lib/ConfigParser$py.class
import: import distutils.command.install # precompiled from /Users/veleno/jython2.5b1/Lib/distutils/command/install$py.class
running install
import: import distutils.command.build # precompiled from /Users/veleno/jython2.5b1/Lib/distutils/command/build$py.class
running build
running build_py
copying twisted/_version.py -> build/lib/twisted
import: 'Integer' as java class
import: 'Long' as java class
Traceback (most recent call last):
  File "setup.py", line 97, in <module>
    main(sys.argv[1:])
  File "setup.py", line 97, in <module>
    main(sys.argv[1:])
  File "setup.py", line 92, in main
    setup(**setup_args)
  File "./twisted/python/dist.py", line 47, in setup
    return core.setup(**get_setup_args(**kw))
  File "/Users/veleno/jython2.5b1/Lib/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/Users/veleno/jython2.5b1/Lib/distutils/core.py", line 151, in setup
    dist.run_commands()
  File "/Users/veleno/jython2.5b1/Lib/distutils/dist.py", line 974, in run_commands
    self.run_command(cmd)
  File "/Users/veleno/jython2.5b1/Lib/distutils/dist.py", line 994, in run_command
    cmd_obj.run()
  File "/Users/veleno/jython2.5b1/Lib/distutils/command/install.py", line 513, in run
    self.run_command('build')
  File "/Users/veleno/jython2.5b1/Lib/distutils/cmd.py", line 333, in run_command
    self.distribution.run_command(command)
  File "/Users/veleno/jython2.5b1/Lib/distutils/dist.py", line 994, in run_command
    cmd_obj.run()
  File "/Users/veleno/jython2.5b1/Lib/distutils/command/build.py", line 112, in run
    self.run_command(cmd_name)
  File "/Users/veleno/jython2.5b1/Lib/distutils/cmd.py", line 333, in run_command
    self.distribution.run_command(command)
  File "/Users/veleno/jython2.5b1/Lib/distutils/dist.py", line 994, in run_command
    cmd_obj.run()
  File "/Users/veleno/jython2.5b1/Lib/distutils/command/build_py.py", line 97, in run
    self.build_packages()
  File "/Users/veleno/jython2.5b1/Lib/distutils/command/build_py.py", line 415, in build_packages
    self.build_module(module, module_file, package)
  File "/Users/veleno/jython2.5b1/Lib/distutils/command/build_py.py", line 378, in build_module
    return self.copy_file(module_file, outfile, preserve_mode=0)
  File "/Users/veleno/jython2.5b1/Lib/distutils/cmd.py", line 371, in copy_file
    return file_util.copy_file(
  File "/Users/veleno/jython2.5b1/Lib/distutils/file_util.py", line 172, in copy_file
    os.utime(dst, (st[ST_ATIME], st[ST_MTIME]))
  File "/Users/veleno/jython2.5b1/Lib/os.py", line 557, in utime
    atimeval = _to_timeval(times[0])
  File "/Users/veleno/jython2.5b1/Lib/os.py", line 574, in _to_timeval
    from org.jruby.ext.posix.util import Platform
ImportError: No module named jruby

comment:7 in reply to: ↑ 2 ; follow-up: Changed 6 years ago by thijs

Replying to glyph:

Signal module derived from one pasted at http://pylonshq.com/pasties/646 - copying it here because pastebins typically aren't permanent.

They added support for signals based on that module: http://bugs.jython.org/issue1074

The builder now fails with: http://buildbot.twistedmatrix.com/builders/ubuntu64-jython2.5-select/builds/102/steps/trial/logs/stdio

so we're one step closer :)

comment:8 in reply to: ↑ 6 Changed 6 years ago by thijs

Replying to vschiavoni:

Currently, the build process fails due to a missing dependency toward jruby:

I tried installing twisted 8.2 on the latest jython trunk (r5970) and it works great (no jruby errors here) but getting some UnicodeDecodeError:

byte-compiling build/bdist.java1.5.0_06/egg/twisted/words/test/test_xpath.py to test_xpath$py.class
byte-compiling build/bdist.java1.5.0_06/egg/twisted/words/test/test_domish.py to test_domish$py.class
byte-compiling build/bdist.java1.5.0_06/egg/twisted/words/test/test_jabberxmppstringprep.py to test_jabberxmppstringprep$py.class
Sorry: UnicodeDecodeError: ('unicodeescape', "u'\\udf42'", 2, 9, 'illegal Unicode character')
byte-compiling build/bdist.java1.5.0_06/egg/twisted/words/test/test_irc.py to test_irc$py.class
byte-compiling build/bdist.java1.5.0_06/egg/twisted/words/test/__init__.py to __init__$py.class

comment:9 in reply to: ↑ 7 Changed 6 years ago by thijs

comment:10 Changed 6 years ago by glyph

  • Author set to glyph
  • Branch set to branches/jython-3413

(In [26586]) Branching to 'jython-3413'

comment:11 Changed 6 years ago by glyph

I'm not intending to merge this branch; every fix here should be explained, tested, and merged separately. However, it's easier to smash the fixes together to push Jython as far along as possible to enumerate the other issues. Also, the Jython folks can run tests against this branch and their fix issues in advance of our patches.

comment:12 Changed 6 years ago by thijs

  • Description modified (diff)

Added some more related tickets to this ticket description.

comment:13 Changed 5 years ago by thijs

  • Description modified (diff)

adding more related tickets to the ticket description

comment:14 Changed 5 years ago by thijs

Our Jython buildslave is now failing with the following error:

Traceback (most recent call last):
  File "./bin/trial", line 22, in <module>
    run()
  File "/home/buildbot/Buildslaves/twisted/jython2.5-thijs-ubuntu/Twisted/twisted/scripts/trial.py", line 363, in run
    test_result = trialRunner.run(suite)
  File "/home/buildbot/Buildslaves/twisted/jython2.5-thijs-ubuntu/Twisted/twisted/trial/runner.py", line 833, in run
    return self._runWithoutDecoration(test)
  File "/home/buildbot/Buildslaves/twisted/jython2.5-thijs-ubuntu/Twisted/twisted/trial/runner.py", line 859, in _runWithoutDecoration
    oldDir = self._setUpTestdir()
  File "/home/buildbot/Buildslaves/twisted/jython2.5-thijs-ubuntu/Twisted/twisted/trial/runner.py", line 749, in _setUpTestdir
    if self._testDirLock.lock():
  File "/home/buildbot/Buildslaves/twisted/jython2.5-thijs-ubuntu/Twisted/twisted/python/lockfile.py", line 125, in lock
    symlink(str(os.getpid()), self.name)
  File "/home/buildbot/Buildslaves/twisted/jython2.5-thijs-ubuntu/Twisted/twisted/python/lockfile.py", line 125, in lock
    symlink(str(os.getpid()), self.name)
AttributeError: 'module' object has no attribute 'getpid'

Seems like a Jython issue to me so opened a ticket for them.

comment:15 Changed 5 years ago by thijs

  • Author changed from glyph to thijs, glyph
  • Branch changed from branches/jython-3413 to branches/jython-3413-2

(In [27705]) Branching to 'jython-3413-2'

comment:16 Changed 5 years ago by thijs

(In [27706]) Merge forward. refs #3413

comment:17 Changed 5 years ago by thijs

Issue with ctypes/Jython is logged at http://bugs.jython.org/issue1554

comment:18 Changed 4 years ago by thijs

fyi, created http://wiki.python.org/jython/TwistedOnJython linking to this ticket.

comment:19 Changed 4 years ago by therve

Thijs: is there a plan to get the buildbot slave back? Progress will stale otherwise.

comment:20 Changed 4 years ago by <automation>

  • Owner glyph deleted

comment:21 Changed 20 months ago by oberstet

  • Cc tobias.oberstein@… added

I was able to get Jython 2.7b1 to run Autobahn/Twisted with 2 minor tweaks. I'd like to discuss those tweaks before going through a proper patch/trial/etc cycle ..

1) Missing builtin.buffer

The following is a workaround due to http://bugs.jython.org/issue1521

Include

# workaround for Jython, see: http://bugs.jython.org/issue1521
import __builtin__
if not hasattr(__builtin__, 'buffer'):
    def _buffer(object, offset = None, size = None):
       if offset is None:
          offset = 0
       if size is None:
          size = len(object)
       return object[offset:offset+size]
    __builtin__.buffer = _buffer

at the beginning of "twisted/python/compat.py".

2) Weird platform ident

Jython identifies itself as "Java" on any platform. I.e. this is on Windows:

Jython 2.7b1 (default:ac42d59644e9, Feb 9 2013, 15:24:52)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys, os
>>> sys.platform
'java1.7.0'
>>> os.name
'java'

Replace

def isWindows(self):
    if self.getType() == 'java':
        import java.lang.System
        realOs = java.lang.System.getProperty('os.name')
        return realOs.lower().startswith("windows")
    return self.getType() == 'win32'

within "twisted/python/runtime.py".

comment:22 follow-up: Changed 20 months ago by oberstet

A more robust way to work around issue 2) is:

class Platform:
    """Gives us information about the platform we're running on"""

    if os.name == 'java' and hasattr(os, '_name'):
        ## see:
        ## http://bugs.jython.org/issue1521
        ## http://bugs.jython.org/msg7927
        osName = os._name
    else:
        osName = os.name
    type = knownPlatforms.get(osName)

comment:23 Changed 17 months ago by normanmaurer

Any progress here ? I would really love to see this happen and so write a maven plugin that use the autobahntestsuite for running tests again a WebSocket server imll.

comment:24 Changed 17 months ago by exarkun

All work on this issue is in the branch referenced in the ticket description. As far as getting a slave goes, we still don't have one.

comment:25 Changed 17 months ago by oberstet

Having been asked, I hereby license the code in my comments above under the MIT license (same as Twisted). Not that I intended anything else anyway ..

comment:26 Changed 17 months ago by oberstet

I just tried Twisted 13.0 / Jython 2.7b1 (already with above patches).

For whatever reasons I now encountered an additional issue: http://bugs.jython.org/issue2060

Workaround: patch twisted/python/threadable.py for

_dummyID = object()
def getThreadID():
    if threadingmodule is None:
        return _dummyID
    try:
        # workaround for broken Jython
        tid = threadingmodule.currentThread().ident
        return tid
    except AttributeError:
        return _dummyID

comment:27 Changed 14 months ago by exarkun

#6745 was a duplicate of this.

Changed 13 months ago by tkanerva

use PY3 implementation of lazyByteSlice for jython2.7 as well

Changed 13 months ago by tkanerva

use PY3 code path in t.i.abstract._concatenate to enable jython

Changed 13 months ago by tkanerva

a workaround for jython thread module to find the thread ID

comment:28 follow-up: Changed 13 months ago by tkanerva

I attached a set of three patches that should enable twisted.web to serve resources under jython 2.7.

There was some talk on #jython as to how to best check for jython at runtime, and the sys.platform string seems to be the most robust approach.

The implementation of checking thread.ident uses exception catching so that it should have a negligible perf impact on CPython (getting the thread ID is a somewhat common operation under many use cases).

comment:29 Changed 13 months ago by tkanerva

  • Cc tkanerva@… added

comment:30 Changed 13 months ago by Arfrever

  • Cc Arfrever.FTA@… added

comment:31 Changed 13 months ago by oberstet

The missing thread ident seems to be fixed http://bugs.jython.org/issue2060 in the upcoming 2.7 release. If the goal is to support Jython >=2.7, then there is no need to work around at least this issue in Twisted ...

comment:32 Changed 13 months ago by thijs

  • Branch changed from branches/jython-3413-2 to branches/jython-3413-3

(In [40022]) Branching to 'jython-3413-3'

comment:33 Changed 13 months ago by thijs

(In [40024]) use PY3 implementation of lazyByteSlice for jython2.7 as well, refs #3413

comment:34 in reply to: ↑ 22 Changed 13 months ago by thijs

  • Description modified (diff)

Replying to oberstet:

A more robust way to work around issue 2) is:

Thanks for reporting this, I've opened a ticket at #6746 and assigned it to you ;)

comment:35 in reply to: ↑ 28 ; follow-up: Changed 13 months ago by thijs

Replying to tkanerva:

I attached a set of three patches that should enable twisted.web to serve resources under jython 2.7.

Thanks for your patches. I merged this branch forward and applied the first one (jython-lazyByteSlice.diff), although slightly changed due to the merge-forward.

When running trial it dies with this error:

/home/thijs/Downloads/jython2.7b1/bin/jython bin/trial twisted
Traceback (most recent call last):
  File "bin/trial", line 17, in <module>
    from twisted.scripts.trial import run
ImportError: No module named trial

The other 2 patches don't apply cleanly, and I expect they also don't fix this trial issue which is crucial if we want to be able to maintain it. Can you create these patches against the current branch and possibly look into this trial issue and see if you can reproduce it?

comment:36 in reply to: ↑ 35 Changed 13 months ago by thijs

Replying to thijs:

When running trial it dies with this error:

/home/thijs/Downloads/jython2.7b1/bin/jython bin/trial twisted
Traceback (most recent call last):
  File "bin/trial", line 17, in <module>
    from twisted.scripts.trial import run
ImportError: No module named trial

This was reported in august 2012, no fix as of yet: http://bugs.jython.org/issue1956

comment:37 Changed 13 months ago by jimbaker

The buffer builtin is now available in Jython trunk, as mirrored here - https://bitbucket.org/jython/jython For the moment, we should only be targeting Jython trunk with any Twisted on Jython work - given that we are actively trying to fix Jython for Twisted. With this in place, we can turn to more interesting problems.

To simplify dependency resolution, I'm actually running a slightly different branch, https://bitbucket.org/jimbaker/jython-ssl, which allows for the use of easy_install. (pip requires slightly more work, including presumably a patch to pip, because it does some crazy/illegal/interesting usage of Unicode, so as to detect illegal Unicode.) So to follow along:

in the git clone of Twisted trunk:

~/jython-dev/jython-ssl/dist/bin/easy_install zope.interfaces
~/jython-dev/jython-ssl/dist/bin/jython setup.py install  # develop should also work

With this, I can repeat not being able to get trial running. However, unlike the bug report here, http://bugs.jython.org/issue1956, I do not get java.lang.ArrayIndexOutOfBoundsException:

$ ~/jythondev/jython-ssl/dist/bin/trial twisted
Traceback (most recent call last):
  File "/Users/jbaker/jythondev/jython-ssl/dist/bin/trial", line 8, in <module>
    execfile(__file__)
  File "/Users/jbaker/jythondev/jython-ssl/dist/bin/trial", line 8, in <module>
    execfile(__file__)
  File "/Users/jbaker/opensource/twisted/bin/trial", line 17, in <module>
    from twisted.scripts.trial import run
ImportError: No module named trial

Running from the Jython console gets the same thing:

$ ~/jythondev/jython-ssl/dist/bin/jython
>>> from twisted.scripts import trial
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name trial

But twisted.scripts itself is available, along with twisted.trial. So something is not getting setup properly it seems. Maybe there's a platform dispatch that has gone wrong?

Let's turn to that issue. I want something to work, so I tried to use treq:

$ ~/jythondev/jython-ssl/dist/bin/easy_install treq

Then run a simple program, like this one:

from treq import get

def done(response):
    print response.code
    reactor.stop()

get("http://www.github.com").addCallback(done)

from twisted.internet import reactor
reactor.run()

This fails with AttributeError: 'module' object has no attribute 'pipe'

The problem here is that the reactor that's selected assumes full Posix, including os.pipe. However, os.pipe is not available on Jython. So it would seem that the solution that's required here is a reactor specific to Jython, much like has been done for Win32.

comment:38 follow-up: Changed 10 months ago by radix

It's rather strange that you get an import error for twisted.scripts.trial -- it's simply a normal module that should exist as twisted/scripts/trial.py on your filesystem. Can you verify that it's actually there? If not, there's probably something wrong with the installation process. It'd be helpful to know what twisted.scripts.file and twisted.scripts.path are at run-time, for information-gathering purposes. There shouldn't be anything strange about them, since we don't do any weird hackery or dynamism with the twisted.scripts package.

comment:39 in reply to: ↑ 38 ; follow-up: Changed 8 months ago by tkanerva

Replying to radix:

It's rather strange that you get an import error for twisted.scripts.trial -- it's simply a normal module that should exist as twisted/scripts/trial.py on your filesystem. Can you verify that it's actually there? If not, there's probably something wrong with the installation process. It'd be helpful to know what twisted.scripts.file and twisted.scripts.path are at run-time, for information-gathering purposes. There shouldn't be anything strange about them, since we don't do any weird hackery or dynamism with the twisted.scripts package.

I investigated this issue further today, and found out the following:

1) twisted/scripts has a non-empty init.py file, which does nontrivial things, and if I modify it to be empty, trial.py and other scripts can be imported.

2) the imports in that init.py themselves aren't probably the culprit, since I can add the imports there and it still works

3) adding the DeprecatedAttribute call from twisted.python.deprecate in init.py seems to be the root cause. I tried to dig deeper into deprecate.py and friends but could not isolate the issue further.

4) despite removing the deprecations from init.py trial still doesn't work properly - it cannot find the plugins necessary for reporter and/or reactor. Doing a --help-reporter gives an empty list, which is odd, since twisted.plugin gets imported correctly (verified that with debug prints).

comment:40 in reply to: ↑ 39 Changed 8 months ago by glyph

Replying to tkanerva:

Replying to radix:

3) adding the DeprecatedAttribute call from twisted.python.deprecate in init.py seems to be the root cause. I tried to dig deeper into deprecate.py and friends but could not isolate the issue further.

deprecatedModuleAttribute is definitely doing some pretty severe metaprogramming (expecting to be able to replace the currently-being-imported module object in sys.modules) so that's a good place to begin your investigation.

4) despite removing the deprecations from init.py trial still doesn't work properly - it cannot find the plugins necessary for reporter and/or reactor. Doing a --help-reporter gives an empty list, which is odd, since twisted.plugin gets imported correctly (verified that with debug prints).

Do the tests for twisted.python.modules work on jython?

comment:41 Changed 2 months ago by hongleij

Twisted14.0/Win8.1/Jython2.7b3

F:\PythonDev\build\Twisted>jython.bat setup.py build
Traceback (most recent call last):

File "setup.py", line 73, in <module>

main(sys.argv[1:])

File "setup.py", line 73, in <module>

main(sys.argv[1:])

File "setup.py", line 55, in main

from twisted.python.dist import (

File ".\twisted\python\dist.py", line 22, in <module>

from twisted import copyright

ImportError: cannot import name copyright

F:\PythonDev\build\Twisted>jython
Jython 2.7b3 (default:5efdcedc9817, Jun 28 2014, 19:17:21)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_05
Type "help", "copyright", "credits" or "license" for more information.

comment:42 Changed 2 months ago by hongleij

Twisted13.2/Win8.1 64bit/Jython2.7b3

Traceback (most recent call last):

File "F:\PythonDev\build\Test2\main.py", line 4, in <module>

from twisted.internet import protocol, reactor, endpoints

File "C:\jython2.7b3\Lib\site-packages\twisted\internet\protocol.py", line 18, in <module>

from twisted.internet import interfaces, error, defer

File "C:\jython2.7b3\Lib\site-packages\twisted\internet\defer.py", line 29, in <module>

from twisted.python import lockfile, log, failure

File "C:\jython2.7b3\Lib\site-packages\twisted\python\lockfile.py", line 23, in <module>

from os import kill

ImportError: cannot import name kill

Jython 2.7b3 (default:5efdcedc9817, Jun 28 2014, 19:17:21)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_05
Type "help", "copyright", "credits" or "license" for more information.

Note: See TracTickets for help on using tickets.