Title: cannot import twisted module
Type: behaviour Severity: major
Components: Core Versions: Jython 2.7
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, amak, fwierzbicki, glyph, thijs, zyasoft
Priority: normal Keywords: twisted

Created on 2012-08-08.12:43:38 by thijs, last changed 2015-11-02.03:26:09 by zyasoft.

msg7354 (view) Author: Thijs Triemstra (thijs) Date: 2012-08-08.12:43:37
For some reason it's not possible to import modules from twisted.scripts with jython, cpython's working fine. This is using Twisted 12.1+.

$ python
Python 2.7.3 (default, Apr 20 2012, 22:39:59) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from twisted.scripts import trial

$ jython
Jython 2.7.0a2+ (default:96bc2fa235a0, Aug 8 2012, 14:26:20) 
[OpenJDK 64-Bit Server VM (Sun Microsystems Inc.)] on java1.6.0_24
Type "help", "copyright", "credits" or "license" for more information.
>>> from twisted.scripts import trial
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name trial
msg7443 (view) Author: Alan Kennedy (amak) Date: 2012-08-28.21:24:28
When I checkout the twisted trunk and try to run it with cpython (without having done a proper install), I get the following error

Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from twisted.scripts import trial
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\temp\trunk\twisted\scripts\", line 9, in <module>
    from twisted.internet import defer
  File "C:\temp\trunk\twisted\internet\", line 25, in <module>
    from twisted.python import log, failure, lockfile
  File "C:\temp\trunk\twisted\python\", line 17, in <module>
    from zope.interface import Interface
ImportError: No module named zope.interface
>>> ^Z

And I see that we have an issue in our bug tracker for zope.interface, related to pyopenssl, although I don't know if that is the cause of this problem.

Issue with zope.interface

Does zope.interface run on jython? Are you using other parts of twisted successfully on jython?

Here is a blog post from 2008 (by Martijn Faassen) discussing porting zope.interface to jython.

Although I don't know what the status of that effort is?

This Twisted ticket says that jython support was removed in 2009

I don't know if it's been reinstated?

I think you should contact the twisted folks and ask them if they expect twisted to run on jython, and if they do, which bits of it?

If you do contact them, please post a link on this ticket.
msg7446 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2012-08-28.21:52:33
Alan: thanks for giving it a try!

The twisted folks are having a monthly meetup local to me (Glyph lives here now) I haven't made it to one yet due to being out of town every time - but I plan on making one soon where I'll see if I can shed light on this.
msg7447 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2012-08-28.21:53:53
BTW nriley fixed all of the zope.interface issues several years ago. If it hasn't bit rotted that shouldn't be the issue.
msg7450 (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) Date: 2012-08-28.22:11:53
About 98.4% of tests of zope.interface-4.0.1 pass with recent snapshot of Jython 2.7:
"Ran 1341 tests in 10.980s

FAILED (failures=7, errors=14)" says that Thijs Triemstra is one of Twisted developers :) .
msg7712 (view) Author: Frank Wierzbicki (fwierzbicki) Date: 2013-02-20.00:16:48
Drat I really need to make it to one of the twisted sprints soon.
msg8118 (view) Author: Thijs Triemstra (thijs) Date: 2013-09-16.22:22:39
One mysterious traceback I'm seeing is the following (tested with python2.7b1 and twisted 13.1+ installed using jython develop). The related twisted ticket for jython support is:

$ /home/thijs/Downloads/jython2.7b1/bin/trial twisted.python
Traceback (most recent call last):
  File "/home/thijs/Downloads/jython2.7b1/bin/trial", line 8, in <module>
  File "/home/thijs/Downloads/jython2.7b1/bin/trial", line 8, in <module>
  File "/home/thijs/workspaces/opensource/software/twisted/svn/Twisted/branches/jython-3413-3/bin/trial", line 7, in <module>
    import _preamble
  File "/home/thijs/workspaces/opensource/software/twisted/svn/Twisted/branches/jython-3413-3/bin/trial", line 7, in <module>
    import _preamble
java.lang.ArrayIndexOutOfBoundsException: 6482
	at org.python.objectweb.asm.ClassReader.readClass(Unknown Source)
	at org.python.objectweb.asm.ClassReader.accept(Unknown Source)
	at org.python.objectweb.asm.ClassReader.accept(Unknown Source)
	at org.python.core.AnnotationReader.<init>(
	at org.python.core.imp.readCode(
	at org.python.core.imp.createFromPyClass(
	at org.python.core.imp.createFromPyClass(
	at org.python.core.imp.loadFromSource(
	at org.python.core.imp.find_module(
	at org.python.core.imp.import_next(
	at org.python.core.imp.import_module_level(
	at org.python.core.imp.importName(
	at org.python.core.ImportFunction.__call__(
	at org.python.core.PyObject.__call__(
	at org.python.core.__builtin__.__import__(
	at org.python.core.imp.importOne(
	at org.python.pycode._pyx23.f$0(/home/thijs/workspaces/opensource/software/twisted/svn/Twisted/branches/jython-3413-3/bin/trial:18)
	at org.python.pycode._pyx23.call_function(/home/thijs/workspaces/opensource/software/twisted/svn/Twisted/branches/jython-3413-3/bin/trial)
	at org.python.core.Py.runCode(
	at org.python.core.__builtin__.execfile_flags(
	at org.python.core.__builtin__.execfile(
	at org.python.core.__builtin__.execfile(
	at org.python.core.BuiltinFunctions.__call__(
	at org.python.core.PyObject.__call__(
	at org.python.pycode._pyx2.f$0(/home/thijs/Downloads/jython2.7b1/bin/trial:10)
	at org.python.pycode._pyx2.call_function(/home/thijs/Downloads/jython2.7b1/bin/trial)
	at org.python.core.Py.runCode(
	at org.python.util.PythonInterpreter.execfile(
	at org.python.util.jython.main(

java.lang.ArrayIndexOutOfBoundsException: java.lang.ArrayIndexOutOfBoundsException: 6482
msg9099 (view) Author: Jim Baker (zyasoft) Date: 2014-10-06.03:29:42
This may slip to 2.7.1 or later, but still targeting 2.7
msg10429 (view) Author: Jim Baker (zyasoft) Date: 2015-11-02.03:26:09
Closing this bug out. There are other issues in running Twisted on Jython, but we can readily import the twisted module and run trial now. See and
Date User Action Args
2015-11-02 03:26:09zyasoftsetstatus: open -> closed
resolution: remind -> out of date
messages: + msg10429
2014-10-06 03:29:42zyasoftsetpriority: high -> normal
assignee: fwierzbicki ->
messages: + msg9099
nosy: + zyasoft
2013-09-16 22:22:40thijssetnosy: + glyph
messages: + msg8118
2013-02-20 00:16:48fwierzbickisetpriority: high
resolution: remind
messages: + msg7712
versions: + Jython 2.7, - 2.7a2
2012-08-28 22:11:53Arfreversetmessages: + msg7450
2012-08-28 21:53:53fwierzbickisetmessages: + msg7447
2012-08-28 21:52:33fwierzbickisetassignee: fwierzbicki
messages: + msg7446
2012-08-28 21:24:29amaksetmessages: + msg7443
2012-08-25 21:09:44amaksetnosy: + amak
2012-08-11 10:43:29Arfreversetnosy: + Arfrever
2012-08-08 17:51:56fwierzbickisetkeywords: + twisted
nosy: + fwierzbicki
2012-08-08 12:43:38thijscreate