Comments (6)
Thanks Scott!
The issue also raises when running on regular python from bash, that was the first thing I tried.
However, you seem to have spotted what the issue was as calling the garbage collector solved the issue (and made me learn about it!).
Thanks, this was very helpful!
from pyabf.
Hi @javierzsm, thanks for reporting this! I can take a closer look this evening.
Can you share the code you are using to iteratively open many ABF files?
from pyabf.
Hi @swharden
Thanks a lot for your quick reply. I copy below the piece of code that reproduce the issue.
I just noticed that it becomes appreciable when opening files => 60-70 Mb each; with smaller files it builds up but more slowly.
Thanks,
Javier
import pyabf
import os
path_data = r'/home/javier/Lab/Data/Ephys/'
for nom_file in os.listdir(path_data):
if nom_file.endswith('.abf'):
print('\nOpening file %s' % nom_file)
abf = pyabf.ABF(path_data + '/' + nom_file)
from pyabf.
Hi @javierzsm,
I do not think this is a bug. I think this is the natural management of memory by Python's garbage collector.
Here's sample code I used to benchmark how much memory is used as I re-load the same ABF files 5,000 times:
import sys
import pathlib
import tracemalloc
import os
import matplotlib.pyplot as plt
import pyabf
if __name__ == "__main__":
abfPath = "2020_06_16_0001.abf"
repetitions = 5000
memoryPerLoad = []
tracemalloc.start()
for i in range(repetitions):
abf = pyabf.ABF(abfPath)
memory = tracemalloc.get_traced_memory()[0]/1e6
memoryPerLoad.append(memory)
print(f"{i+1} of {repetitions}... current memory: {memory} MB")
tracemalloc.stop()
plt.plot(memoryPerLoad)
plt.title(os.path.basename(abfPath))
plt.grid(ls='--', alpha=.5)
plt.ylabel("Process Memory (MB)")
plt.xlabel("ABF Read Count")
plt.show()
If you want to force Python's garbage collector to run manually you can, but this is typically not recommended https://docs.python.org/3/library/gc.html
Do you think this explanation adequately addresses your issue? If you can provide or a sample ABF and sample code that lets me reproduce a bug on my side I'd be happy to look deeper into this. Thanks, and good luck! 👍 🚀
from pyabf.
It may be worth trying to call the garbage collector manually after loading huge files to see if it helps... something like this:
import pyabf
import gc
for i in range(repetitions):
abf = pyabf.ABF("test.abf")
gc.collect()
from pyabf.
Oh! Also I now see you're running that from inside Spyder/IPython.
Does this issue go away if you run it from a console in regular Python?
from pyabf.
Related Issues (20)
- explore support for variable-length sweeps HOT 3
- pyabf compatibility with pyInstaller HOT 4
- Support protocols with user list epoch durations HOT 10
- add type hints and improve documentation
- ABF() should accept a pathlib.Path
- Stop warning when invalid dates are detected
- refactor header reader into smaller files
- AttributeError in module pyabf.tools when trying to use Memtest HOT 2
- Fails to load files with more adc channels than dac channels HOT 3
- ABF.sampleRate
- FFT/Spectrogram analysis of ABF data HOT 10
- Tutorial code - Plot the Command Waveform HOT 1
- add return types to properties HOT 5
- investigate memory management in long-running applications HOT 2
- error: unpack requires a buffer of 1 bytes (end of file reached) HOT 5
- Folder loop with pyabf HOT 2
- parent/child grouping
- ValueError when printing the header HOT 3
- How to read the epoch that a user list is applied to?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyabf.