Skip to content

Instantly share code, notes, and snippets.

@nickmbailey
Created February 1, 2016 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickmbailey/979614eae0f9607616e9 to your computer and use it in GitHub Desktop.
Save nickmbailey/979614eae0f9607616e9 to your computer and use it in GitHub Desktop.
import threading
from _io import _IOBase
def create_gc():
io = _IOBase()
print io
del io
t = threading.Timer(0.001, create_gc)
t.start()
def call_close():
io = _IOBase()
print io
io.close()
t = threading.Timer(0.001, call_close)
t.start()
for i in range(30):
t1 = threading.Timer(1.0, create_gc)
t1.start()
t2 = threading.Timer(1.0, call_close)
t2.start()
@nickmbailey
Copy link
Author

Demonstrates a deadlock bug in jython. First apply this patch:

diff --git a/src/org/python/modules/_io/PyIOBase.java b/src/org/python/modules/_io/PyIOBase.java
index 09f052d..7e1550c 100644
--- a/src/org/python/modules/_io/PyIOBase.java
+++ b/src/org/python/modules/_io/PyIOBase.java
@@ -733,6 +733,7 @@ public class PyIOBase extends PyObject implements FinalizableBuiltin, Traversepr

     @Override
     public void __del_builtin__() {
+        System.out.println("Deleting io object.");
         closer.dismiss();
         invoke("close");
     }

Then run the above script:

java -cp dist/jython-standalone.jar org.python.util.jython repro.py

You will see the script stop outputting and enter a deadlocked state before very long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment