
from threading import Thread

import h5py

FNAME = "deadlock.hdf5"

def make_file():
    with h5py.File(FNAME,'w') as f:
        for idx in xrange(1000):
            f.attrs['%d'%idx] = 1

def list_attributes():
    with h5py.File(FNAME, 'r') as f:
        names = list(f.attrs)

if __name__ == '__main__':

    make_file()
    thread = Thread(target=list_attributes)
    thread.start()
    list_attributes()
    thread.join()


from threading import Thread
import sys

import h5py

FNAME = "deadlock.hdf5"

def make_file():
    with h5py.File(FNAME,'w') as f:
        for idx in range(1000):
            f.attrs['%d'%idx] = 1

def list_attributes():
    with h5py.File(FNAME, 'r') as f:
        names = list(f.attrs)

if __name__ == '__main__':

    make_file()
    thread = Thread(target=list_attributes)
    thread.start()
    list_attributes()
    thread.join()

Make deadlock script work on Python 3
Make deadlock script work on Python 3

  
  from threading import Thread
+ import sys
  
  import h5py
  
  FNAME = "deadlock.hdf5"
  
  def make_file():
      with h5py.File(FNAME,'w') as f:
-         for idx in xrange(1000):
+         for idx in range(1000):
              f.attrs['%d'%idx] = 1
  
  def list_attributes():
      with h5py.File(FNAME, 'r') as f:
          names = list(f.attrs)
  
  if __name__ == '__main__':
  
      make_file()
      thread = Thread(target=list_attributes)
      thread.start()
      list_attributes()
      thread.join()
  
Make deadlock script work on Python 3
## Code Before:

from threading import Thread

import h5py

FNAME = "deadlock.hdf5"

def make_file():
    with h5py.File(FNAME,'w') as f:
        for idx in xrange(1000):
            f.attrs['%d'%idx] = 1

def list_attributes():
    with h5py.File(FNAME, 'r') as f:
        names = list(f.attrs)

if __name__ == '__main__':

    make_file()
    thread = Thread(target=list_attributes)
    thread.start()
    list_attributes()
    thread.join()

## Instruction:
Make deadlock script work on Python 3
## Code After:

from threading import Thread
import sys

import h5py

FNAME = "deadlock.hdf5"

def make_file():
    with h5py.File(FNAME,'w') as f:
        for idx in range(1000):
            f.attrs['%d'%idx] = 1

def list_attributes():
    with h5py.File(FNAME, 'r') as f:
        names = list(f.attrs)

if __name__ == '__main__':

    make_file()
    thread = Thread(target=list_attributes)
    thread.start()
    list_attributes()
    thread.join()
