« first day (1580 days earlier)      last day (3385 days later) » 

5:02 PM
cbg!
guys how can I stop a infinity-loop function with an another function from outside?
 
pep8 doesnt recommend empty __init__ methods does it?
ive never heard of that?
 
@KeremZaman Give us an example
 
An infinity loop sounds awesome. They need one in the new avengers.
 
def Blink(pin):
    while True:
        OnOff(True,pin)
        time.sleep(0.25)
        OnOff(False,pin)
        time.sleep(0.25)
for example this function I need to stop it from outside when it is necessary
 
Change while True to while someVariable, where someVariable is some variable that can be modified from outside the function.
See also:
260
Q: Is there any way to kill a Thread in Python?

Sudden DefIs it possible to terminate a running thread without setting/checking any flags/semaphores/etc.?

I'm assuming you're using threading, because non-threaded Python applications can't have code executing inside a loop and at the same time have code executing somewhere else
 
DSM
5:19 PM
@Ffisegydd: I was thinking more like it was a name for a cool move you might use at the X-Games.
 
wait that is old
 
oh, you are right I must use threading
 
or is it a dupe ... there was another Blink question
with some guy calling it from php exec
 
either use threads or hack up some semaphore equivalent with an empty file or something
 
thanks guys for your advices, especiallly @Kevin
 
5:21 PM
3
A: exit for loop from another python script

Joran Beasleywhile not os.path.exists("/home/pi/stop_LEDS"): do_blink_led() os.remove("/home/pi/stop_LEDS") then in the php just create that file ... when you want it to stop you could make it exist with <?php exec('touch /home/pi/stop_LEDS');?> try this index.php <?php if isset($_POST["stop"...

 
import threading
import time

keep_going = True

def infinity_loop():
    i = 0
    while keep_going:
        print "looped {} times".format(i)
        time.sleep(0.1)
        i += 1

t = threading.Thread(target=infinity_loop)
t.start()
time.sleep(3)
keep_going = False
raw_input("press enter to exit")
 
lol, infinity loop
def blinkenlights would've been better though
 
thanks @Kevin and @JoranBeasley
 
You mustn't modify the variables a blinkenlights function depends on, because it "IST NICHT FÜR DER GEFINGERPOKEN UND MITTENGRABEN".
;-)
 
took you a while to look it up ;)
 
5:23 PM
I'm operating at limited efficiency because it's lunch time :-)
 
end of day and work weed, yay Sun-Thu workweeks in UTC+2
s/weed/week/g of course
 
I was about to say, we don't get many members of that subculture in here ;-)
 
I used to indulge when I was younger, doesn't mix well with root access
 
Was just about to check if Amsterdam is in UTC+2.
 
I think it is, actually
 
DSM
5:25 PM
I've had my suspicions from time to time, but I'm of course far too polite to raise them in public.
 
damn, PyCharm is such a memory hog
 
Wikipedia delivers: it's in UTC+2 during daylight savings time, UTC+1 otherwise
 
so, has anyone migrated any largeish projects to py3 yet?
 
I migrated KevinScript to 3 last month. it's 2000-ish lines.
 
DSM
I haven't bothered migrating anything; instead I just started writing new projects in 3 a few years ago after the stack was ported.
 
5:31 PM
Uh, but I may have broken forward compatibility by putting some unparenthesized prints in code since then. I still test mostly on 2.7
 
I'm considering an experiment with py3, but my production runs on pypy so not much point
 
man
@sliceAndValidate(PRIMARY)
def cookTEMPC(self, R, coefs={}):
log = getMathFunction("log", R)
x = log((4095./R) - 1)
x = self.addSymbol(x, "x")
return 25.01914 + x * (-22.8437 + x * (1.532076 -0.08372 * x))
 
user559633
@MarkR. what's largish? i have a 20k loc app running on 3.4
 
sometimes I cy
cry
thats alot of work to get the temperature from a raw sensor value
 
Luckily I have zero external dependencies, so the usual outcry of "but 3.X doesn't have good library support" doesn't matter to me.
 
5:32 PM
@tristan, let me count LOCs, it isn't that big... just handles ~200k QPS during peak time
 
@Kevin: ditto that, but sometimes I forget I don't have to do everything from scratch
 
@JoranBeasley That's some complex looking code.
@ljetibo Yeah, if it was anything but a pure passion project, I would have downloaded lex/yacc or something long long ago.
 
at least I found it ... thats litterally the only documentation we have to decode a certain sensor value
 
But since KS is merely a fun hobby, I can say "I reject all that was not invented here" without harming anyone.
 
DSM
What is coefs? Mutable default argument which doesn't even seem to be referred to?
 
5:35 PM
legacy code is fun
 
user559633
@AnttiHaapala thanks :)
 
"coefficients", I expect
 
its a generic function that sometimes accepts coefficients
 
Nailed it!
 
it is a signature that is required because the wrapper calls it with coefs that come from user prefs
its painful sometimes to sledgehammer things to fit an existing thing ... instead of just redoing it better
 
5:37 PM
@tristan, 20.5k LOC
 
coefs gets used in sensors that measure volumetric water content ... its a dict of {"A":1e-12,"B":2e-6,...}
 
tornado app
 
Hmm, I converted 2k LOC in a day, so 20k LOC should take a week or so???
 
overall the code works pretty well ... except for some cases where you really add complication due to the templated calls and expected outputs of that fn
 
Probably less if you're more dedicated than me, which isn't hard
 
5:39 PM
I don't even think it would be that much of a problem, not many prints or antiquated dependencies
I'd need to run a ton of benchmarks though
 
I maintain LOCs don't mean jack....
 
currently handling something like 400 QPS per core with PyPy
 
I agree locs dont mean much ... more locs = more bugs
 
DSM
Depends on the style of programming. Some stuff converts easily, others not so much.
 
re-cbg
 
5:41 PM
Now I'm second guessing my own memory. I think it was PEP 8 compliance that took a day, and 2to3 conversion took an hour.
 
Mostly I think it depends on the sys, I've a stuuuupid prog that searches lines on images for my minor on 60TB, (still at it though, probably like 21-24k now) most of the lines jsut handle the files and formats ("science standards" mybe like 5k do the actual detection...
 
I'm always PEP8-compliant thanks to pycharm
 
and all that file handling is necessary because it's run on a cluster(fuck)
so half the things doesn't exist
 
I'm compliant to everything except "keep lines below 80 characters", because I'm a rebel
 
DSM
Exist, all the things!
 
5:43 PM
@Kevin, +1 to that, 80 lines is way too narrow even in portrait mode
80 columns
tired
 
@DSM : sry :D half the things don't exist*
?
 
If you're trying to browse my github on your 16x20 Atari console, sorry if you have to scroll right
 
user559633
@ljetibo yes, LOC doesn't mean anything, but to answer the question of "has anyone moved over a large codebase," it's helpful
 
2to3 would most likely cover 99% of everything aside from crappy stuff in branches/derp/scratch.py
 
user559633
most of the stuff that was incompatible was stuff i knew i shouldn't have been doing anyway
 
5:46 PM
pycharm always tells me I am writing code that is not py3 compatible :P ... i ignore those warnings ... since this codebase will likely never go to py3
 
I really like py3 though
I thinkit's a nice step from py2
 
user559633
i'm holding out for 2.9
 
especially all the work they did in generators and I really like metaclassess, although I've still not come up with a reason why they exist
 
DSM
Aside from library improvements, Python 3 fixed a number of design flaws in 2, so I was happy to switch after it settled down and the ecosystem was ported.
 
user559633
.items() hooray
 
5:48 PM
still took me a while to start putting () on print statements
 
I still dont really understand why they changed that to make it a function instead of a statement? ...
 
there's a pep for that
give me a sec
 
DSM
I would have done it just to get rid of print "something", which is really ugly. (The trailing comma, I mean.)
 
5:52 PM
basically it's the return type that's been bugging them, now print returns jsut strings, before it returned >>> print ("Hello", "world")
('Hello', 'world') and in 3 it's "Hello World"
 
yeah Ive read it ... it just doesnt resonate with me
print statement returns nothing (not even None)
@DSM ok thats a reasonable annoyance... but one that rarely comes up (at least for me)
 
DSM
Conceptually, it fits in much better as a function than as a keyword -- it's a lot more like sys.stdout.write than it is if or for.
 
but couldnt they have just made a new function (ie printf...) or even just modified sys.stdout.write to take the additional print arguments? and left print as a statement
it just is because im used to it as a statement I know ... and eventually i will get used to it being a fn
its the classic "but ... but... its different! ... "
 
at least it isn't PHP's pants-on-head approach
 
The nice thing about it being a function is that it's introspectable by ipython and pycharm
 
DSM
5:58 PM
Oh, I hate new things myself, you don't have to sell me on that-- but if I were designing a language from scratch, it honesty would never have occurred to me to make print anything other than a function.
 
I think it's mostly about large program friendliness, If you have print without () you can't tell where the print line starts where it ends. when debugging locally it's maybe a good idea to use them, but when launching you would probably want to just replace all the prints with sys.stderr.write() (or whatever). This is easier done when print has () and regex than it's when it doesn't?
 
/me quietly deletes Statement -> PrintStatement from KevinScript's language.txt file
 
Same with exec being a function like eval, you can get help on them now.
 
Theoretically, regex isn't strong enough to find the ")" at the end of a function call. You'd always be able to trick it with something like print(")))))")
 
@ljetibo huh?
 
DSM
6:00 PM
Well, help("exec") was never that hard to type, but you have a point.
 
why cant you tell where it begins and ends?
 
I always forget about help, I'm always using ? in ipython.
 
I mean in production you should be using logging imho ...
where as I use prints ...for debug garbage that I really dont want in a log file
(I know its not the best debug practice ... but meh :P)
 
@beasley: multiline prints? print """I am \
god"""
@kevin: but you wouldn't need to because sys.stdout is a function and needs them anyhow, all you have to find is the print
it was also just an example :D
 
show me someone who doesnt use prints to debug sometimes and ill show you a liar :P
 
DSM
6:02 PM
Being able to do function?? and get the code is one of my favourite things in the world.
 
lol is that a py3 thing?
 
@JoranBeasley, I don't actually use prints... I have a badass logging.py everywhere ;)
 
Ive never seen that
 
no, that's py2 it won't work like that in py3
no ()
 
oh cool
I didnt know you could do that
neat
 
6:02 PM
>>> print "I am \
god" works as well
 
I learn new stuff sometimes I guess :P
 
>>> def f():
...     return 23
...
>>> f??
  File "<stdin>", line 1
    f??
     ^
SyntaxError: invalid syntax
It doesn't work :-(
 
/sadface
 
DSM
>>> def f():
...     return 23
...
>>> f??
Type:        function
String form: <function f at 0x7f67801ab6e0>
File:        /home/dsm/coding/<ipython-input-5-d55d58409c2b>
Definition:  f()
Source:
def f():
    return 23
 
doesnt work for me either :(
 
6:03 PM
@JoranBeasley: I like my 65 char line limit :D
 
what python is that?
 
DSM
IPython, for the win.
 
iPython, it seems
 
o its iPython magic
I see
 
yeah, I like it's notebook idea, I hate that hidden magic though (at time import statement order matters, that kills me)
 
6:04 PM
ipython + django-extensions is massively useful
 
iPython does funny things for me ... (it takes a lot longer to start than normal console... and it seems to leave my console in a funny state if I exit the ipython terminal and dont restart)
dont close the console window I mean
(not restart my computer)
 
are you on windows?
 
DSM
We've used the notebook interface when we needed to let one of our less-technically-minded people explore some data.
 
its been very useful when I use it but the annoyances typically outweigh the benifits
yeah Im on windows :(
 
I'm dual boot, currently on win, Ipython on win only
 
6:07 PM
I do like the notebook thing though ...
 
python on windows is awkward most of the time, yeah
 
but again when im in the terminal its usually just to test quick stuff
 
yeah, the entire to pdf to html to whatever thing is awesome
 
and it takes me longer to start notebook than to do the test I need
 
does anyone remember the name of that JSON-based WSDL equivalent?
 
6:09 PM
rest?
:P
 
user559633
json-wsp?
 
now that's a name that inspires confidence
"your function causing problems? Silence it with our special katana method!"
 
haha
 
isnt dojo a javasccript thing?
 
6:11 PM
yeah
 
also anyone here ever saw the fuckit module? :D Oh man that was the best thing I've read ever....
 
lol nope ... I thought it was funny the other day I saw in a linkedin thread someone promoting their python password manager ... named :pysswords
 
which just made me think of bodily functions
 
give at least the readme a read. But the sourcecode is just gem stacked on a gem
 
user559633
6:13 PM
i'm going to start writing a bash-based web framework
 
yeah, that stuff is weapons-grade
bash is too good, use COBOL
 
def test_context_manager():
with fuckit:
pass
assert 'P' != 'NP' # proof is left as an excercise for the reader
 
goddamn uwsgi
there really needs to be a better way
 
app.run() is pretty easy :P
 
deployment just gets so awkward now
new things are bad
 
6:16 PM
yeah i just use apache2 + mod-wsgi ... its pretty easy in general ... not as easy as app.run() clearly :P
 
nginx + supervisor + uwsgi for prod most of the time
 
Ive been too scared to try uwsgi ... apache2+mod-wsgi was hard enough the first dozen times
 
haven't used apache in years
 
@MarkR. dont you have an IT department to handle deployment :P
 
user559633
what's wrong with uwsgi?
 
6:18 PM
@JoranBeasley, do you even devops, bro? :(
 
/addasanatask IT : create uwsgi deployment for python codebase
 
this client can't afford fulltime IT, and I'm a consultant, so I just bill them 2x for any system-related stuff
ends up about the same as having 2 guys on call 24x7
can't afford = won't pay for, they can definitely afford it
 
user559633
heh. how long is your contract?
 
Answer a question two minutes ago. thirty seconds ago, OP comments on his own post saying, "so does anyone know how to do this?" :-I
 
user559633
6:20 PM
my experience has been that people "won't" afford it until they start eating outages and work stoppage
 
@tristan, we renegotiate every year or so
they get a day a week on-site, more or less
no outages that the app is to blame for yet, been in prod for a couple of years
 
I suck at deployment stuff ... tbh I would probably tell them up front that I suck at that :P
and then try anyway
 
so just subcontract it out and bill 3x
 
and probably inadvertantly leave gaping security holes
 
user559633
someone (cough) has a company that does deployment on contract
 
6:21 PM
I started out as a sysadmin originally anyway
even got my RHCE at one point
 
yeah I can google "how to host python with apache2"
:P
 
user559633
eh. python + uwsgi + nginx is peanut butter + jelly + bananas
 
@tristan I'll keep that in mind next time i need a deployment :P (rarely ... I tend to not do much web work)
 
I suck at anything web related, and I don't hate it because I suck, but I do dislike it.
 
6:23 PM
I actually have a "naked" tornado app that needs CPU pinning and fancy LB configs and other stuff
1 dockerfile later, tap-tap-send-bill
 
user559633
why CPU pinning?
 
'cause no points in using threads, the app shares state via redis
each proc gets a core and a port
sustains ~6k reqs/sec per server, with ~200k concurrent connections
the 200k is overall
 
thats pretty reasonabl
how do you benchmark that?
 
siphon some prod traffic and try to kill a server every once in a while
 
6:27 PM
I'm also obliged to answer in under 20ms
 
I was wondering if there was a free "let us ddos your site for you and tell you how it works"
 
json in, json or 204 out
 
Servers... The Most Dangerous Game.
 
@JoranBeasley, there's tons of stress-testing services
but your workload can really affect performance, because static file serving won't be the same as actual business logic etc
 
DSM
We used to have a guy here who did it for free..
 
6:28 PM
yeah ... but its typically at home where I dont want to pay :P or for a client where I really dont want to see the results
 
I use cProfile a lot
apparently datetime.new() is horrifically slow in PyPY
or rather new or whatever
__new__
ah that works
 
yeah I profile plenty ... for bottlenecks ... but the internets may as well be black magic to me
 
@JoranBeasley, my app isn't a standard web app, it's an OpenRTB DSP, so not much overlap with standard web patterns if at all
 
DSM
> "Let us turn ours into a country of mushrooms by making mushroom cultivation scientific, intensive, and industrialized!"
And on that note, time for lunch.
 
but generally, anything that goes outside of the app or container itself can and will be slow (databases, files, etc)
 
6:32 PM
@Kevin +1 for turtle :P
whoa you used some words I dont know
OpenRubarbTastingBar and LCD DSP
 
lol
 
Bah - anyone got a decent rep on scifi.stackexchange.com ?
 
ahhh google
 
@JoranBeasley, it's basically a decision engine that determine whether the client should buy a specific impression opportunity or not
tl;dr: spend $ on internet ad banners
 
Uh, I've got 171 points.
Is that decent?
 
6:35 PM
yeah I googled it
I think i have 101 points :P
 
oh damn, I should get on that thing
they should base initial rep on Goodreads imports
 
yeah nothing on the front page looks all that interesting
lots of harry potter
 
also look at the post before my edit ;_;
 
did you install it in a venv?
 
"Hulk vs Goku" on hold?!?! This is a travesty!
 
6:37 PM
@MarkR. Are you asking me? That's not my question...
 
Inquiring minds want to know.
 
oh yeah, heh
 
was hoping to get more attention by throwing after bounty at:
9
Q: Story with children that have magical powers imbued by wearing stones around their neck

Jon ClementsI believe I first read this in the mid/late 80s. Here what's I can recall: It involved a boy and a girl - I believe 7-10 years old - I don't recall if they were friends or brother and sister They were given a "stone" on a string necklace that enabled magic and protection of some sort from some ...

 
I think that on Windows, all that stuff goes under $PYTHONHOME\Scripts
 
yeah
or $PYTHONHOME\tools
typically at least
 
6:40 PM
Tools seems to be new
I think I had 2.7.6 on my windows box, and everything went to scripts
 
ahh Tools\Scripts
i guess that maybe scripts that come with python rather than 3rd party
or something
thats where 2to3.py lives
 
yeah but scripts would have, like, 2to3.bat
 
on 2.6.6 at least (dont laugh :P)
 
and you'd have 2to3 in $PATH
brb tea
 
@tristan np :D
 
6:42 PM
I dont have 2to3.bat in my scripts
anyway I add both those to my path :P
 
@tristan actually that is pretty stupid, I think bc stackoverflow is such a "pro-microsoft shop" then you need to support IE5 that does not like pngs?
@MarkR. there is no $PATH either in windows ;)
 
user559633
Yeah, I'm not sure either. I also don't understand why SE is so pro-microsoft (or maybe they're not, but that's my impression)
 
because of joel? :D
 
@AnttiHaapala %PATH%
what makes you think SE is pro-ms?
 
@JoranBeasley just was pointing out that you haven't graduated Windows ;)
 
6:45 PM
I have linux box at home ... but it cant play some games even with wine
so windows stays
as far as work its cause our clients run mostly windows so thats our OS too
 
I do not say it is "pro-ms" necessarily but it is set up by ex-microsoftie guys running on windows and the foremost target users in the beginning were the guys doing windows dev
 
well because if you are on linux you probably dont have quite as simple questions ... there is probably some basic understanding of how programming works
>>> I think bc stackoverflow is such a "pro-microsoft shop"
:P
 
s/stackoverflow/stackexchange/
 
user559633
meta.stackexchange.com/questions/32516/… it's not like it's an obscure thought
 
bc I did develop for dos, windows, did visual basic, visual C++, etc, etc and so on and then I was like "meh"
 
user559633
6:48 PM
i stopped hating myself, so i stopped supporting windows. or maybe it was the other way around.
 
in the turn of the millennium I had the feeling that MS is just the toy and Unixen are where the real work is done
I sometimes think maybe I should do some windows development... to find out if I still hate it
I have actually never touched .NET really
 
I think the first answer on that meta nails it ... largely just more cs101 students use windows than linux ... and they have more problems
I never touch .net and I develope almost exclusivly for windows
(I do ocassionally use win32api
)
about 30% of all questions asked on Stack Overflow are related to Microsoft technologies
It's possible that 30% of currently used technologies (world wide) are Microsoft technologies. .... also explains the pheonomonom
 
7:05 PM
.NET was pretty damn awesome when it came out
compared to ATL/MFC and all that crap
I remember being in awe of C# and WinForms
 
@Grant: :-D No need to apologise to me though. — Martijn Pieters 11 secs ago
Hehe.
Question was about a certain URL, I helped work around a headers issue (doctype in the headers), that's the web dev responsible.
 
user559633
The CV queue is pretty large. I don't understand why SE hasn't upped the number of reviews allowed per day
 
@JoranBeasley eek
 
user559633
A post that basically contains "Should SE increase the number of close-votes a user can cast to clear out the backlog?" be a poor question for meta.stackoverflow?
 
user2555451
 
user559633
7:17 PM
Thanks @iCodez -- searched and didn't see it
 
7:39 PM
@BhargavRao, it's a dupe of the question he should be asking, but doesn't know enough to ask.
 
@Kevin Use thy super powers
 
I don't feel comfortable doing so, because 1) his actual question didn't contain the word raw_input anywhere, and 2) If he's not familiar with raw_input, then reading the target question will do him no good, and he'll just post another question like this one
 
Oh. The question is now answered, so it is better to leave it alone
 
7:54 PM
C++ teacher forced to make a lesson plan with Python, spotted
 
DSM
Heh
Pity the poor student, though.
 
Yeah
 
lol I like what he's doing with total_cost there
 
The question just might be answerable if we discover what void means, though!
Is it just "a function that doesn't return anything"? He already has one of those.
 
DSM
If we replace "void function" with "function which returns None" then the assignment seems to make sense, at least.
When I first saw it, I thought the problem would be about writing a function which accepted another function, but that doesn't seem to be the case.
Okay, now I have to go see what data my happy little minions have found for me. Here's hoping!
 
7:58 PM
Ok, I think his question is actually "my program doesn't run right, how can I fix it?", in which case the answer is "change your parameters"
 
DSM
.. and fix your function.
 
I have taken pity on the child.
 
me too :P
 
"one of these surely might be what you want". But what if neither are what he wants? :-D
At the very least, I think he wants his function to print something on its own.
 
nay I say
 
8:05 PM
Ok.
 
:P
there I added example 1.0005
what kind of stupid assignment would teach that ...
>:(
or maybe its just interpretation
 
A C++ teacher would.
Which isn't to say C++ teachers are bad. Rather, any teacher is bad if the administration forces them to shoehorn their lessons into an unrelated subject.
 
well you win this round Kevin :P
 
Thus quelling the roaring emptiness inside me... Briefly.
 
8:26 PM
Hmm, OP is reading from a book rather than a teacher's lesson plan... This upsets me.
 
cbg
 
I advise he burns that book... and purges anything it said from his brain
 
8:51 PM
@BhargavRao, I don't really like solutions involving split and join, because it turns newlines and consecutive whitespace characters into single spaces.
Ex. "this____whitespace__is___significant" gets compressed to "this whitespace was significant"
(imagine those underscores are spaces, the markdown engine would have eaten them otherwise)
 
user559633
whitespace should never be considered important
 
I'm surprised no one recommended a natural language processing library for that question or anything.
I guess the pros are all asleep.
 

« first day (1580 days earlier)      last day (3385 days later) »