473,766 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"ulimit -s" has no effect?


I use this simple test in Python:

def foo(i):
print i
foo(i+1)
import sys
sys.setrecursio nlimit(1000000)
foo(0)

Now, my understanding is that I get the segfault when Python overruns the C
stack. Naturally the last number printed should go up when I increase the
stack size in the shell before calling Python, by using "ulimit -s <number
of k>". But this seems to not be the case. Whatever value I use with
ulimit, Python always segfaults at the same recursion depth. Any advice on
how to get things to work proper with this?

% python -V
Python 2.3.3
% uname -a
Linux isildur 2.4.24-1-686 #1 ...
Jul 18 '05 #1
16 3413
Maciej Kalisiak wrote:
Now, my understanding is that I get the segfault when Python overruns the C
stack. Naturally the last number printed should go up when I increase the
stack size in the shell before calling Python, by using "ulimit -s <number
of k>". But this seems to not be the case. Whatever value I use with
ulimit, Python always segfaults at the same recursion depth. Any advice on
how to get things to work proper with this?


As a starting point, verify that the limit you set actually does get
set. It may be that you don't have permission to increase your stack
limit.

Regards,
Martin

Jul 18 '05 #2
"Martin v. Löwis" <ma****@v.loewi s.de> writes:
As a starting point, verify that the limit you set actually does get
set. It may be that you don't have permission to increase your stack
limit.


I check that it is set by running "ulimit -s" without a numerical argument.
The reported value is the one I have set, viz. much larger than the default of
8192 (kbytes). This is the soft limit. The hard limit is reported to be
"unlimited" .

If it matters, let me add that I'm running Python from within zsh.
% zsh --version
zsh 4.0.4 (i686-pc-linux-gnu)

--
Maciej Kalisiak | <mac at dgp.toronto.edu > | http://www.dgp.toronto.edu/~mac [McQ]
Jul 18 '05 #3
Maciej Kalisiak wrote:
If it matters, let me add that I'm running Python from within zsh.
% zsh --version
zsh 4.0.4 (i686-pc-linux-gnu)


Have you tried it with a different shell? Your example works for me
as expected. But I'm using a bash where ulimit is a builtin. Don't
know about zsh.

Mathias

Jul 18 '05 #4
Mathias Waack <M.*****@gmx.de > writes:
Have you tried it with a different shell? Your example works for me
as expected. But I'm using a bash where ulimit is a builtin. Don't
know about zsh.


"ulimit" is a builtin in zsh as well. But I did try under "bash" from a Linux
console. Same behaviour. On two different machines. This must be something
embarassingly simple. Sanity check, just to be on the same page, here's my
procedure:

1. % python
2. # type in routine
def foo(i):

print i
foo(i+1)

3. >>> foo(0)
4. this properly raises exception at depth 998 or so
5. import sys
6. sys.setrecursio nlimit(1000000)
7. >>> foo(0)
8. segfaults at about depth 7000+
9. % ulimit -s 32000
10. repeat steps 1 through 7
11. same segfault point

--
Maciej Kalisiak | <ma*@dgp.toront o.edu> | http://www.dgp.toronto.edu/~mac
Jul 18 '05 #5
On Fri, 5 Feb 2004, Maciej Kalisiak wrote:
I check that it is set by running "ulimit -s" without a numerical argument.
The reported value is the one I have set, viz. much larger than the default of
8192 (kbytes). This is the soft limit. The hard limit is reported to be
"unlimited" .


I have no idea whether this affects Linux, but some pthreads
implementations hard code the stack size for the "primary" or
"initial" thread.

Python is built with thread support if possible (incl on Linux), but
without explicit use of the thread support Python code runs in the context
of the "primary" thread.

ISTR that RedHat, amongst others, changed thread implementations
relatively recently.

I know that there is/was a bug in the Python bug tracker on SF related
to this issue on Linux (symptom is test_sre dumping core) with Python
2.3.3. This particular issue is sensitive to the version of gcc and
optimisation settings (& on Linux, whether the Python core is in a SO),
as newer releases/higher optimisation settings result in larger stack
frames.

--
Andrew I MacIntyre "These thoughts are mine alone..."
E-mail: an*****@bullsey e.apana.org.au (pref) | Snail: PO Box 370
an*****@pcug.or g.au (alt) | Belconnen ACT 2616
Web: http://www.andymac.org/ | Australia

Jul 18 '05 #6
Andrew MacIntyre <an*****@bullse ye.apana.org.au > writes:
I have no idea whether this affects Linux, but some pthreads
implementations hard code the stack size for the "primary" or
"initial" thread.

Python is built with thread support if possible (incl on Linux), but
without explicit use of the thread support Python code runs in the context
of the "primary" thread.

ISTR that RedHat, amongst others, changed thread implementations
relatively recently.

I know that there is/was a bug in the Python bug tracker on SF related
to this issue on Linux (symptom is test_sre dumping core) with Python
2.3.3. This particular issue is sensitive to the version of gcc and
optimisation settings (& on Linux, whether the Python core is in a SO),
as newer releases/higher optimisation settings result in larger stack
frames.


Interesting.

1. Is there a test or code snippet that I can run to confirm that this is what
ails my system?

2. If this *is* the problem, what would be a good workaround?
For the record I am using Debian's sid/unstable distribution.
debs used:
python 2.3.2.91-1
libc6 2.3.2.ds1-8

"ldd" shows python uses libpthreads, and it comes from the above libc6
package.

Upgraded Python to debian package 2.3.3-5; no change.
Jul 18 '05 #7
On Fri, 6 Feb 2004, Maciej Kalisiak wrote:
1. Is there a test or code snippet that I can run to confirm that this is what
ails my system?
A trivial C program can be used to demonstrate:

---8<--- stest.c ---8<---
#include <stdio.h>

int recursion_func( int t1, int t2, int t3);

int main(void)
{
printf("counter = %d\n", recursion_func( 25, 15, 1));
return 0;
}
---8<------8<-------8<---
---8<--- rfunc.c ---8<---
int recursion_func( int t1, int t2, int t3)
{
int z1, z2, z3;
double x1, x2, x3;

z1 = t1 << 2;
z2 = t2 << 2;
z3 = t3 << 2;

x1 = 3.47 * z1;
x2 = 1.29 * z2;
x3 = -2.47 * z3;

return x1 * x2 - x3 > 1.5e30 ? t3 : recursion_func( ++t1, ++t2, ++t3);
}
---8<------8<-------8<---

Note that the recursion function was made more complex than might have
been needed to try to force larger stack frames. I was also trying to
avoid gcc's optimiser undoing the recursion at higher levels of
optimisation - this worked with gcc 2.95, but gcc 3.3.2 seems to be able
to make this test non-recursive even with -Os ... :-|

On FreeBSD, this is built by

$ gcc -g -O -pthread -c rfunc.c
$ gcc -g -O -pthread -c stest.c
$ gcc -g -O -pthread -o stest stest.o rfunc.o

You'll have to adapt for Linux. Running this:

$ ./stest
Bus error (core dumped)
$ gdb stest stest.core
GNU gdb 4.18 (FreeBSD)
{...copyright stuff elided...}
Program terminated with signal 10, Bus error.
Reading symbols from /usr/lib/libc_r.so.4...d one.
Reading symbols from /usr/libexec/ld-elf.so.1...done .
#0 0x80484ce in recursion_func (t1=21846, t2=21836, t3=21822)
at pthread_recursi on_test_aux.c:3
3 int recursion_func( int t1, int t2, int t3)
(gdb)
libc_r is the pthread-supporting libc.

Building without the "-pthread" switch uses the non-threaded libc, which
results in:

$ ./stest
Segmentation fault (core dumped)
$ gdb stest stest.core
{...}
Program terminated with signal 11, Segmentation fault.
Reading symbols from /usr/lib/libc.so.4...don e.
Reading symbols from /usr/libexec/ld-elf.so.1...done .
#0 0x8048530 in recursion_func (t1=1398102, t2=1398092, t3=1398078)
at pthread_recursi on_test_aux.c:1 6
16 return x1 * x2 - x3 > 1.5e30 ? t3 : recursion_func( ++t1,
++t2, +
+t3);
(gdb)
In this case, I know the stack size is 64MB; the ratio t1 values between
the two matches 1MB to 64MB.
2. If this *is* the problem, what would be a good workaround?


If you can do without threads, build the Python interpreter that way.

I suggest that you enquire of glibc forums whether there is any way to
tweak the primary thread stack size by some runtime means, otherwise
the only option would probably require changing a library header file and
recompiling glibc :-( (which is what's required on FreeBSD 4.x - don't
know about 5.x).

--
Andrew I MacIntyre "These thoughts are mine alone..."
E-mail: an*****@bullsey e.apana.org.au (pref) | Snail: PO Box 370
an*****@pcug.or g.au (alt) | Belconnen ACT 2616
Web: http://www.andymac.org/ | Australia

Jul 18 '05 #8
> def foo(i):
print i
foo(i+1)
import sys
sys.setrecursio nlimit(1000000)
foo(0)


This entire thread begs the question: Why are you recursing this deep?
It would be faster to iterate.

- Josiah
Jul 18 '05 #9
Josiah Carlson <jc******@nospa m.uci.edu> writes:
def foo(i):
print i foo(i+1)
import sys
sys.setrecursio nlimit(1000000)
foo(0)


This entire thread begs the question: Why are you recursing this deep?
It would be faster to iterate.


The algorithm calls for it: Tarjan's algorithm for finding the
Strongly-Connected Component (SCC) of a graph. If there is an equally
efficient iterative approach, I'd like to hear of it.

I don't think I need to recurse to depth 1,000,000 , but definitely higher
than 7k.
Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3997
by: Susanna | last post by:
Hi all, I'm using the following slideshow script that I found on the web to display changing images with a crossfade effect. Eventually I will be adding many more images to the slideshow. The thing is, I ALSO have to make it so the images will load randomly. I have looked at a number of scripts for random-loading slideshows, but I have to find a way to COMBINE this fading-image script (or, a different fading-image script, if...
8
431
by: pertheli | last post by:
I am in a situation where only "goto" seems to be the answer for my program logic where I have to retry calling some repeated functions. Can anybody help in the usage of goto and its effect in local variables, as shown in the stripped code below void MyClass:Process(){ int iMaxRetry = 100;
7
8011
by: Gary Duncan | last post by:
Hi all, My first incursion into this group so apologies if the following question is misplaced. That is, I'm trying to find some free javascript which implements the "ken burns effect" on images, eg .jpegs in a CD slideshow, or similar.
14
2853
by: Charles Douglas Wehner | last post by:
If you go to http://www.netscape.com and search for Wehner, you will find my site. It will say http://wehner.org You click to preview, and find that my home page is too big for the preview window. So you scroll, and things happen.
16
14563
by: eholz1 | last post by:
Hello CSS group, I saw a beautiful effect that I would like to use either by CSS or using photoshop to create the image/effect (maybe even imagemagick) the site address is: http://victor.hasselblad.com/. the lead image here is a white photograph (jpeg) on a white background, with a shadow like effect around the entire image. In this case the shadow effect is part of the jpeg, and not
3
5262
by: Beamer | last post by:
Hi I am trying to build a roating slide effect in javascript. Basically, I have a list like below <ul id="slideShowCnt"> <li id="slide0"><img .../></li> <li id="slide0"><img .../></li> <li id="slide0"><img .../></li> <li id="slide0"><img .../></li> <li id="slide0"><img .../></li> <li id="slide0"><img .../></li>
3
2410
by: Gandalf | last post by:
Sharp effect is one of the photoshop effect on letters. some one a javascript script that create the same effect? thanks
7
2860
by: nolo contendere | last post by:
the alert message appears before the Effect.SlideUp even begins. How can I ensure that the SlideUp completes before executing the next statement? I've tried setTimeout, and I can kind of get it to work, but that seems very kludgy, and may not work in all cases. TIA ===================== function add_entry( id ) {
2
2653
by: AndrewC | last post by:
I am using the Scriptaculous/Prototype libraries to build a project and I really want to have an effect like the mootools download page (http://www.mootools.net/download) where when you mouse over the lines at the bottom very fast, the lines do not highlight. They only highlight if your mouse is over them for slightly longer. Sadly, I can't use the mootools library, so I am hoping someone can point me in the right direction. I am...
0
1356
by: Chocolade | last post by:
I created a new form and added split container and then on the left side a treeview and on the treeview i added nodes and on the right side of the split container i added a groupbox. Now in the groupbox i added a checkbox and what i wanted to do is when its checked it will activate voices on my program i mean SpeechSynthesizer() And its working when i check in the checkbox it says "Voices are now enabled" and when uncheck it says " Voices...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10008
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9837
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.