Skip to content

decorator for clean file closing for PyPy compatability (migrated from Trac #597) #588

Closed

Description

@networkx-trac

Original ticket https://networkx.lanl.gov/trac/ticket/597
Reported 2011-07-15 by @bjedwards, assigned to @bjedwards.

Address an issue where file handles aren't closed immediately by the garbage collector in PyPy. By creating a decorator we for functions which do io, we can tell what they send (pathname or filehandle) and close the file if they send a path.

Code at:

https://bitbucket.org/bedwards/networkx-bedwards/src/d96d13a0bf58/networkx/utils/decorators.py

Activity

  1. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by @bjedwards, 2011-07-15

    We need to change the files that do IO to use this.

  2. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by @hagberg, 2011-09-11

    This was updated. Now works with pypy. See #632.

  3. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by @hagberg, 2011-09-11

    Errors with the partial numpy are pretty awful but I don't think we can do anything (easily) about that:

    '''

    import networkx as nx
    G=nx.path_graph(4)
    nx.eigenvector_centrality(G)
    {0: 0.3717482342712009, 1: 0.6015008315175004, 2: 0.6015008315175004, 3: 0.3717482342712009}
    nx.eigenvector_centrality_numpy(G)
    Traceback (most recent call last):
    File "", line 1, in
    File "/home/aric/.local/lib/python2.7/site-packages/networkx/algorithms/centrality/eigenvector.py", line 155, in eigenvector_centrality_numpy
    A=nx.adj_matrix(G,nodelist=G.nodes())
    File "/home/aric/.local/lib/python2.7/site-packages/networkx/linalg/spectrum.py", line 57, in adj_matrix
    return nx.to_numpy_matrix(G,nodelist=nodelist,weight=weight)
    File "/home/aric/.local/lib/python2.7/site-packages/networkx/convert.py", line 526, in to_numpy_matrix
    M = np.zeros((nlen,nlen), dtype=dtype, order=order)
    TypeError: zeros() got an unexpected keyword argument 'order'
    '''

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions