pydemo | Python code demonstration console for didactic purposes | Interpreter library
kandi X-RAY | pydemo Summary
kandi X-RAY | pydemo Summary
pydemo provides a command line interpreter which emulates the behavior of the interactive Python interpreter. In addition, it can read files Python files and execute them by blocks. The CLI processes all the files and splits them in code blocks. A certain number of empty lines in files (1 by default) are used to identify the boundaries between blocks, although they are also validated to verify that they are syntactically correct. In negative case, next lines are added until the accumulated block is right. Each time no text is introduced in the CLI (just pressing ENTER key) a new block is executed. It is print (with syntax highlighted if Pygments is installed) and then it is evaluated inside the CLI, so that in next command you may use objects instantiated inside the code block.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Push the given line to the console .
- Returns a list of code blocks
- Parse command line arguments .
- Generate a demo history console .
- Get requirements from requirements . txt
- Initialize history .
- Replace readline .
- Example demo .
- Initialize the console .
pydemo Key Features
pydemo Examples and Code Snippets
Community Discussions
Trending Discussions on pydemo
QUESTION
I want to read a file, 4 lines by 4 (it's a fastq file, with DNA sequences).
When I read the file one line by one or two by two, there's no issues, but when I read 3 or 4 lines at once, my code crashes (kernel appeared to have died on jupyter notebook). (Uncommenting the last part, or any 3 out of the 4 getline()
.
I tried with a double array of char (char**) to store the lines, with the same issue.
Any idea what can be the cause ?
Using Python 3.7.3, Cython 0.29, all other libraries updated. File being read is about 1.3GB, machine has 8GB, ubuntu 16.04. Code adapted from https://gist.github.com/pydemo/0b85bd5d1c017f6873422e02aeb9618a
...ANSWER
Answered 2021-Apr-26 at 11:27The underlying problem was my misunderstanding of getline()
getline() c reference
To store lines in different variables, an associated n
is necessary for each line pointer *lineptr
.
If *lineptr is set to NULL and *n is set 0 before the call, then getline() will allocate a buffer for storing the line.
Alternatively, before calling getline(), *lineptr can contain a pointer to a malloc(3)-allocated buffer *n bytes in size. If the buffer is not large enough to hold the line, getline() resizes it with realloc(3), updating *lineptr and *n as necessary.
The n
(or seed
in my code) will hold the size of the buffer allocated for the pointer, where getline() puts the incoming line. As I set the same buffer variable for different pointers, getline was given the wrong information of the size of the char* line_xxx.
As fastq files are usually in this shape:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install pydemo
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page