[1.1.0] Jython 2.7: urllib.FancyURLopener only works the first time after import urllib --- Jython problem --- workaround

Bug #1464105 reported by R_Richie on 2015-06-11
14
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Sikuli
Medium
RaiMan

Bug Description

************ workaround

run script from command line after having edited and saved it in IDE

------------------------------------------

I use SikliX 1.1.0
Code like this:

import urllib
opener = urllib.FancyURLopener({})
f = opener.open("http://www.python.org/")
print f.read()

六月 11, 2015 11:29:24 上午 org.python.netty.channel.AbstractChannel$AbstractUnsafe register
警告: Force-closing a channel whose registration task was not accepted by an event loop: [id: 0x1d496cfb]
java.util.concurrent.RejectedExecutionException: event executor terminated
at org.python.netty.util.concurrent.SingleThreadEventExecutor.reject(SingleThreadEventExecutor.java:745)
...
at _socket$py.connect$80(E:\sikuli\sikulix.jar\Lib\_socket.py:888)
at _socket$py.call_function(E:\sikuli\sikulix.jar\Lib\_socket.py)
...
at httplib$py._send_output$28(E:\sikuli\sikulix.jar\Lib\httplib.py:854)
at httplib$py.call_function(E:\sikuli\sikulix.jar\Lib\httplib.py)
...
at urllib$py.open$14(E:\sikuli\sikulix.jar\Lib\urllib.py:211)
at urllib$py.call_function(E:\sikuli\sikulix.jar\Lib\urllib.py)
...
at org.python.pycode._pyx1226.f$0(E:\sikuli\workspace\testpost.sikuli\testpost.py:4)
at org.python.pycode._pyx1226.call_function(E:\sikuli\workspace\testpost.sikuli\testpost.py)
...
[error] script [ testpost ] stopped with error in line 3
[error] IOError ( [Errno socket error] error(-1, u'Unmapped exception: java.util.concurrent.RejectedExecutionException: event executor terminated') )

.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1386)
at org.python.core.__builtin__.execfile_flags(__builtin__.java:535)
at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:286)
at org.sikuli.scriptrunner.JythonScriptRunner.runPython(JythonScriptRunner.java:209)
at org.sikuli.scriptrunner.JythonScriptRunner.runScript(JythonScriptRunner.java:177)
at org.sikuli.ide.SikuliIDE$ButtonRun$1.run(SikuliIDE.java:2369)

I guess this may connect with Jython.

RaiMan (raimund-hocke) on 2015-06-11
summary: - when I use Python package to post some message, it'll throw exception
+ [1.1.0] Jython 2.7: urllib.FancyURLopener only works the first time
+ after import urllib
description: updated
summary: [1.1.0] Jython 2.7: urllib.FancyURLopener only works the first time
- after import urllib
+ after import urllib --- Jython problem
summary: [1.1.0] Jython 2.7: urllib.FancyURLopener only works the first time
- after import urllib --- Jython problem
+ after import urllib --- Jython problem --- workaround
RaiMan (raimund-hocke) wrote :

for such special Python/Jython module problems you have to go to the Jython homepage and look out for a solution or bug report.

description: updated
Changed in sikuli:
status: New → Confirmed
importance: Undecided → Medium
assignee: nobody → RaiMan (raimund-hocke)
milestone: none → 1.1.0
R_Richie (r-richie-7) wrote :

Thank you for your answer.
I use "os.popen()" to open the python script which can do post.
using this way ,I can do it again.

szczuro (szczur0) wrote :

I had similar problem with urllib/urllib2, script worked in sikuli 1.0.1 but in 1.1.0 not
Finally I made connection through java, since jython could import java modules

from java.net import URL
def callURL(self, url): URL(url).openConnection().getInputStream()

Terje Kerlefsen (terje-x) wrote :

Same here. It worked in Windows 7, then I tried Linux Mint but got the error above. First thought it could be a Windows/Linux incompatibility issue but after checking it turned out that i had Sikuli 1.0.1 on the Windows PC and 1.1.0 on Linux Mint PC. Seems as repeating urllib2.urlopen() when the Sikuli script is running works OK in 1.1.0, it's when you rerun the script without restarting Sikuli IDE the error appears. The bug is a bit annoying so i added a check if it is a rerun in the beginning of the script and if it is popup a message saying the IDE has to be restarted.

try:
  if rerun:
     popup("urllib2.urlopen() will not work when repeating Run in Sikuli IDE so close IDE before rerun")
except:
  rerun = True

Krzysztof Guć (krzysiek-q) wrote :

Hi All.

Hi Guys, J found Solution:

try add something that in header:

import sys, _socket
if _socket.NIO_GROUP.isShutdown():
    print "RE-CREATEING NIO_GROUP"
    _socket.NIO_GROUP = _socket.NioEventLoopGroup(2, _socket.DaemonThreadFactory("PyScan-Netty-Client-%s"))
    sys.registerCloser(_socket._shutdown_threadpool)

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers