[Tutor] Issue with wsgi_ref.simple_server - sometimes very slow!

2017-06-02 Thread Attila Szabó
Hi All,

I'm facing a really strange behavior with python's wsgi_ref.simple_server
module.

I have the following setup:
- Raspberry Pi 2
- Ubuntu Mate 16.04
- Python3.5
-

I have the following simple source:
#!/usr/bin/env python3
import wsgiref.simple_server

def my_func(env, start_response):
  start_response('200 OK', [])
  return [''.encode()]

server = wsgiref.simple_server.make_server(
  '0.0.0.0',
  19891,
  my_func,
)

server.serve_forever()
After several requests (around every ~5 requests) the response time is
getting really-really slow (1-60sec) compared to the average 0.1s response,
the server serves the request and then quick again for couple of new
requests and then againgetting to be slow...

I'm trying to reach the node via my router, and also from outside internet
and the latency is there.

I have tried the same code also on Windows10 with same python version, from
behind the same router and the issue was not present.
Also I have removed the router and connected internet directly to Raspberry
PI and I faced the same issue.
So I think I can say that that is not because of the router for sure.

Also, always when I interrupt the running server I'm getting the following
exception:
Exception happened during processing of request from ('192.168.1.100', 3540)
Traceback (most recent call last):
  File "/usr/lib/python3.5/socketserver.py", line 313, in
_handle_request_noblock
self.process_request(request, client_address)
  File "/usr/lib/python3.5/socketserver.py", line 341, in process_request
self.finish_request(request, client_address)
  File "/usr/lib/python3.5/socketserver.py", line 354, in finish_request
self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.5/socketserver.py", line 681, in __init__
self.handle()
  File "/usr/lib/python3.5/wsgiref/simple_server.py", line 119, in handle
self.raw_requestline = self.rfile.readline(65537)
  File "/usr/lib/python3.5/socket.py", line 575, in readinto
return self._sock.recv_into(b)
KeyboardInterrupt
That's why I think there is some issue with that recv_into function, but I
cannot figure it out how to resolve this... :/


Does anybody faced this same issue? Or anybody has an idea what should I
try or what should I modify in python source to solve this issue?

Thanks,
Attila
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] threading tutorial

2017-06-02 Thread Michael C
ihave to look at this tomorrow, thanks for the reply!



On Thu, Jun 1, 2017 at 6:18 PM Alan Gauld via Tutor 
wrote:

> On 01/06/17 16:30, Michael C wrote:
> > Oh i get it alright, however in my code I have to push the W button like
> > this:
> >
> > import pyautogui
> > import time
> >
> > pyautogui.keyDown('w')
> > time.sleep(2)
> > pyautogui.keyUp('w')
>
> So this emulates a user pressing the w key for 2 seconds.
> What's not clear is where this appears in your design,
> is it part of the code running in the thread or is it
> part of the code that stops the thread?
>
> If you can explain a little bit more of the high level
> requirement hee rather than the implementation perhaps
> we can come up with a better solution - ideally one
> that doesn't involve any keypress emulation at all...
>
> > while the example you gave:
> >
> >  def fn():
> >global run_me
> >while run_me:
> >  ... do some work ...
> >
> > and then elsewhere you go:
> >
> >  global run_me
> >  run_me = True
> >  ... create and start the Thread ...
> >  ... later ...
> >  run_me = False
> >  T.join()
> >
> > theoretically deals with my problem, in practice though, my function
> spend
> > almost all its time holding down the 'w' button,
>
> The fact you say the function suggests you mean the thread.
> So the question is why does it need to hold the key down
> for so long? Indeed why does a background process need
> to emulate a button press? What is the button press doing?
> Is it in turn detected by some other process/thread? We
> need to understand how the various bits interact to give
> a better solution.
>
> > Is there a way to pause/kill the thread?
>
> Not really other than setting a flag, but if its the
> thread that's doing the sleeping then killing it
> won't help - in fact if you could kill it in the
> middle of the sleep() you'd have the problem of
> a key being "held down" forever - probably a
> bad thing... Thats why its better to have the
> thread kill itself on detection of the semaphore.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Issue with wsgi_ref.simple_server - sometimes very slow!

2017-06-02 Thread Alan Gauld via Tutor
This appears to be a duplicate of the message you sent on 31st May.
Please don not send multiple copies of the same message, it fragments
the threads and messes up the archives for searching. One message is
sufficient, if you don't get a response it probably means nobody
knows the answer (or maybe your question was insufficiently specific,
although that's not an issue here). If you want to clarify the issue
send a follow-on to your own message, please don't start a new thread.

Thanks

Alan G.
Moderator.

On 02/06/17 07:20, Attila Szabó wrote:
> Hi All,
> 
> I'm facing a really strange behavior with python's wsgi_ref.simple_server
> module.
> 
> I have the following setup:
> - Raspberry Pi 2
> - Ubuntu Mate 16.04
> - Python3.5
> -
> 
> I have the following simple source:
> #!/usr/bin/env python3
> import wsgiref.simple_server
> 
> def my_func(env, start_response):
>   start_response('200 OK', [])
>   return [''.encode()]
> 
> server = wsgiref.simple_server.make_server(
>   '0.0.0.0',
>   19891,
>   my_func,
> )
> 
> server.serve_forever()
> 

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pasting an image with transparency

2017-06-02 Thread Alan Gauld via Tutor
On 01/06/17 20:34, Terry wrote:
> Slackware 14.2 64-bit
> Python 2.7.13
> 
> I am trying to automate some photo processing by pasting a
> sig or watermark. The sig image is a .png with transparency
> but when it pastes it does so with a black background. Is there
> a way to paste with transparency?
> 

I believe there is a Pillow support forum, this is probably
better addressed to the PIL experts there.

https://python-pillow.org/

Or possibly even to a general imaging/graphics discussion forum.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pasting an image with transparency

2017-06-02 Thread Peter Otten
Terry wrote:

> Slackware 14.2 64-bit
> Python 2.7.13
> 
> I am trying to automate some photo processing by pasting a
> sig or watermark. The sig image is a .png with transparency
> but when it pastes it does so with a black background. Is there
> a way to paste with transparency?
> 
> 
> 
> from PIL import Image
> from PIL import ImageEnhance
> 
> fname = "sample.jpg"
> 
> im = Image.open(fname)
> print(im.format, im.size, im.mode)
> 
> out = im.resize((1068, 712))
> 
> enh = ImageEnhance.Sharpness(out)
> enh = enh.enhance(2.5)
> 
> sig =
> Image.open("/home/tvbare/pics/recent_pics/sigs/opi_sig_landscape.png")
> print(sig.format, sig.size, sig.mode)
> box = (768, 616, 1018, 662)
> enh.paste(sig, box)
> 
> enh.show()
> 

We read the docstring so you don't have to ;)

>>> from PIL import Image
>>> image = Image.open("sample.jpg") # some random pic I have lying around
>>> help(image.paste)
Help on method paste in module PIL.Image:

paste(im, box=None, mask=None) method of PIL.JpegImagePlugin.JpegImageFile 
instance

[...]
Note that if you paste an "RGBA" image, the alpha band is
ignored.  You can work around this by using the same image as
both source image and mask.
[...]

So let's try that. (Since I don't have a transparent picture handy I'm using 
a copy of 
.)

>>> stamp = Image.open("transparent.png")
>>> image.paste(stamp, (0, 0), mask=stamp)
>>> image.show()

Seems to work...


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] New blog that has solution for python programs

2017-06-02 Thread meenu ravi
Hello,

I'm planning to create a blog that provides solution with explanation for
python programming challenges available in websites like Hackerearth,
codecademy, etc., so that if others also share their solution along with
explanation in the same blog, it will be helpful for beginners. I wanted to
make sure that it's not illegal to share solution like that. I have seen
solutions available in different websites. So I hope its legal. But still
wanted to confirm with views of people in large forum. I felt it may be
spoon-feeding the programmers, but I was able to find solutions for almost
all the programs when I searched.

Thanks,
Meena
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New blog that has solution for python programs

2017-06-02 Thread Japhy Bartlett
The only legal concern is if you're copying challenges directly from the
sites; someone has some sort of ownership and copyright on the code and
description.

Don't copy / paste anything and you'll be fine.  If you do, check the
license first (it may be open source).




On Fri, Jun 2, 2017 at 12:29 PM meenu ravi  wrote:

> Hello,
>
>
>
> I'm planning to create a blog that provides solution with explanation for
>
> python programming challenges available in websites like Hackerearth,
>
> codecademy, etc., so that if others also share their solution along with
>
> explanation in the same blog, it will be helpful for beginners. I wanted to
>
> make sure that it's not illegal to share solution like that. I have seen
>
> solutions available in different websites. So I hope its legal. But still
>
> wanted to confirm with views of people in large forum. I felt it may be
>
> spoon-feeding the programmers, but I was able to find solutions for almost
>
> all the programs when I searched.
>
>
>
> Thanks,
>
> Meena
>
> ___
>
> Tutor maillist  -  Tutor@python.org
>
> To unsubscribe or change subscription options:
>
> https://mail.python.org/mailman/listinfo/tutor
>
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Coming from R, what's a good IDE editor? I've tried PyCharm and Spyder

2017-06-02 Thread C W
Dear Python list,

I am an R user learning Python. What is a good editor?

1) Pycharm
PyCharm evaluates the entire script, I just want to change a few lines in
the script.
For example,

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0, 1,0.1)
y = np.sin(2 * np.pi * x)

plt.figure(1)
plt.clf()
plt.plot(x, y)
plt.show()

Now, I want to do a scatter plot, but don't want to generate the data
again. I just want the "line by line" evaluation like in R and Matlab.
Basically, you can type in console and add to the existing variables.

2) Spyder
Spyder looks a lot like RStudio, I like it! But, it does not have an app
icon in applications.  I am baffled. I do ~/anaconda/bin/spyder every time.

Am I missing something or is this the way it is?

Thank you very much!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New blog that has solution for python programs

2017-06-02 Thread Mats Wichmann
On 06/02/2017 11:27 AM, meenu ravi wrote:
> Hello,
> 
> I'm planning to create a blog that provides solution with explanation for
> python programming challenges available in websites like Hackerearth,
> codecademy, etc., so that if others also share their solution along with
> explanation in the same blog, it will be helpful for beginners. I wanted to
> make sure that it's not illegal to share solution like that. I have seen
> solutions available in different websites. So I hope its legal. But still
> wanted to confirm with views of people in large forum. I felt it may be
> spoon-feeding the programmers, but I was able to find solutions for almost
> all the programs when I searched.

Seems like it helps defeat the purpose of such sites if the answers are
all located in one place...


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pasting an image with transparency

2017-06-02 Thread Terry



On 06/02/2017 08:31 AM, Peter Otten wrote:

Terry wrote:

We read the docstring so you don't have to ;)


 I have to remember to utilize available help functions... my bad.


from PIL import Image
image = Image.open("sample.jpg") # some random pic I have lying around
help(image.paste)

Help on method paste in module PIL.Image:

paste(im, box=None, mask=None) method of PIL.JpegImagePlugin.JpegImageFile
instance

[...]
 Note that if you paste an "RGBA" image, the alpha band is
 ignored.  You can work around this by using the same image as
 both source image and mask.
[...]

So let's try that. (Since I don't have a transparent picture handy I'm using
a copy of 
.)


stamp = Image.open("transparent.png")
image.paste(stamp, (0, 0), mask=stamp)
image.show()

Seems to work...


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


I first posted my question to the image-sig list but never got a reply.

Awesome! Thank you for responding.

--
Terry "Hoots"

 To stay young, never lose your sense of wonder.


 *
 My main photo gallery can be seen at:
   http://www.flickr.com/photos/tvbare/>

  I also keep a secondary gallery at:
http://www.facebook.com/pages/Osage-Plains-Images/300412117042>

 *

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New blog that has solution for python programs

2017-06-02 Thread Danny Yoo
I'm not a fan of the idea of publishing solutions of coding challenge
problems because it often violates the honor codes of institutions. Even if
some sites are okay with this, the majority probably are not.

Rather than muddy the water, might be best to skirt the issue.

What is the problem you're trying to solve, though?  It's laudable that you
want to help, so perhaps there's something else you can do that's both
effective and not as controversial.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New blog that has solution for python programs

2017-06-02 Thread Danny Yoo
Legality is the lowest of bars.  We should aim higher.

I'm pretty sure that the listed sites should strongly prefer *not*  to have
solutions available like this.

The more I think about this, the more I'm tending to say: don't do this.
It may feel like charity, but the authors of the problem sets will not look
at this kindly.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New blog that has solution for python programs

2017-06-02 Thread Steven D'Aprano
On Fri, Jun 02, 2017 at 05:00:37PM -0700, Danny Yoo wrote:
> Legality is the lowest of bars.  We should aim higher.
> 
> I'm pretty sure that the listed sites should strongly prefer *not*  to have
> solutions available like this.
> 
> The more I think about this, the more I'm tending to say: don't do this.
> It may feel like charity, but the authors of the problem sets will not look
> at this kindly.

I don't think "what the authors might want" is the only factor here. 
Personally, I think these programming challenge sites probably do more 
harm than good, discouraging people that they're not good enough to be a 
programmer because they can't solve the (often exceedingly tricky) 
problems on their own. I think they're often dick-measuring contests, 
for elite programmers to show off and sneer at "lesser mortals" who 
can't solve the problems.

In the real world, nobody has to solve these sorts of problems under the 
constraints given. In real life programming, you get to look for 
existing solutions, you get to consult with your colleagues, pass ideas 
back and forth, etc. If you need a solution to X, and your colleague 
already solved it for another project, you say "Hey Fred, I'm stealing 
your code" and if Fred gets upset you talk to his project manager who 
tells Fred to cooperate.

(Well, that's the way it is in companies that are not dysfunctional.)

These problems are the very definition of Solved Problems. They have 
been solved thousands of times!

They're fine for people who *enjoy* this sort of challenge, but I 
believe that for every one of them, there are probably a hundred or a 
thousand programmers who do not enjoy these challenges, who are 
discouraged by them, but who would learn a lot from being able to read 
and re-use the solutions.

That's just my opinion. People may disagree.



-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New blog that has solution for python programs

2017-06-02 Thread meenu ravi
Thank you all for your views. I was hesitating for the same reason. Now I'm
clear that I shouldn't go for a blog that gives straightforward solution
for the challenges.

Thanks,
Meena

On Jun 2, 2017 7:30 PM, "Steven D'Aprano"  wrote:

> On Fri, Jun 02, 2017 at 05:00:37PM -0700, Danny Yoo wrote:
> > Legality is the lowest of bars.  We should aim higher.
> >
> > I'm pretty sure that the listed sites should strongly prefer *not*  to
> have
> > solutions available like this.
> >
> > The more I think about this, the more I'm tending to say: don't do this.
> > It may feel like charity, but the authors of the problem sets will not
> look
> > at this kindly.
>
> I don't think "what the authors might want" is the only factor here.
> Personally, I think these programming challenge sites probably do more
> harm than good, discouraging people that they're not good enough to be a
> programmer because they can't solve the (often exceedingly tricky)
> problems on their own. I think they're often dick-measuring contests,
> for elite programmers to show off and sneer at "lesser mortals" who
> can't solve the problems.
>
> In the real world, nobody has to solve these sorts of problems under the
> constraints given. In real life programming, you get to look for
> existing solutions, you get to consult with your colleagues, pass ideas
> back and forth, etc. If you need a solution to X, and your colleague
> already solved it for another project, you say "Hey Fred, I'm stealing
> your code" and if Fred gets upset you talk to his project manager who
> tells Fred to cooperate.
>
> (Well, that's the way it is in companies that are not dysfunctional.)
>
> These problems are the very definition of Solved Problems. They have
> been solved thousands of times!
>
> They're fine for people who *enjoy* this sort of challenge, but I
> believe that for every one of them, there are probably a hundred or a
> thousand programmers who do not enjoy these challenges, who are
> discouraged by them, but who would learn a lot from being able to read
> and re-use the solutions.
>
> That's just my opinion. People may disagree.
>
>
>
> --
> Steve
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New blog that has solution for python programs

2017-06-02 Thread Danny Yoo
Steven says:

>> I don't think "what the authors might want" is the only factor here.
>> Personally, I think these programming challenge sites probably do more
>> harm than good, discouraging people that they're not good enough to be a
>> programmer because they can't solve the (often exceedingly tricky)
>> problems on their own.

[cut]

>> They're fine for people who *enjoy* this sort of challenge, but I
>> believe that for every one of them, there are probably a hundred or a
>> thousand programmers who do not enjoy these challenges, who are
>> discouraged by them, but who would learn a lot from being able to read
>> and re-use the solutions.
>>
>> That's just my opinion. People may disagree.


Hi Steven,

Yes, that's a good point.  I do need to be careful of myself: I have a
strong tendency to think in terms of black and white.

Thanks for keeping me honest.


I think the kind and the quality of the problem is a big factor.  If
it's of the vanilla, intro-to-programming variety, I think caution is
warranted.  If it's a more difficult programming challenge problem,
then because it has enough density and complexity, the problem won't
just fall apart like cotton candy from discussing it, so that's ok
too.

The source of the problem also contributes another dimension.  If it's
coming from a book like Steven Skiena's "Programming Challenges", then
I think it's perfectly ok to share and reuse solutions.  If it's
coming from some university homework problem set, I have some
reservations.


This topic is very much in the zeitgeist, by the way:


https://thenextweb.com/dd/2017/05/30/lets-teach-computer-science-students-to-cheat/#.tnw_YelJZVuo

https://www.nytimes.com/2017/05/29/us/computer-science-cheating.html?_r=2


> Thank you all for your views. I was hesitating for the same reason. Now I'm
> clear that I shouldn't go for a blog that gives straightforward solution
> for the challenges.

Meena, I do want to add: if you do something like this, focus on the
process rather than the end-solution, because that's the part that's
worthwhile.


Good luck!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New blog that has solution for python programs

2017-06-02 Thread meenu ravi
Great, thanks!

On Jun 2, 2017 10:26 PM, "Danny Yoo"  wrote:

> Steven says:
>
> >> I don't think "what the authors might want" is the only factor here.
> >> Personally, I think these programming challenge sites probably do more
> >> harm than good, discouraging people that they're not good enough to be a
> >> programmer because they can't solve the (often exceedingly tricky)
> >> problems on their own.
>
> [cut]
>
> >> They're fine for people who *enjoy* this sort of challenge, but I
> >> believe that for every one of them, there are probably a hundred or a
> >> thousand programmers who do not enjoy these challenges, who are
> >> discouraged by them, but who would learn a lot from being able to read
> >> and re-use the solutions.
> >>
> >> That's just my opinion. People may disagree.
>
>
> Hi Steven,
>
> Yes, that's a good point.  I do need to be careful of myself: I have a
> strong tendency to think in terms of black and white.
>
> Thanks for keeping me honest.
>
>
> I think the kind and the quality of the problem is a big factor.  If
> it's of the vanilla, intro-to-programming variety, I think caution is
> warranted.  If it's a more difficult programming challenge problem,
> then because it has enough density and complexity, the problem won't
> just fall apart like cotton candy from discussing it, so that's ok
> too.
>
> The source of the problem also contributes another dimension.  If it's
> coming from a book like Steven Skiena's "Programming Challenges", then
> I think it's perfectly ok to share and reuse solutions.  If it's
> coming from some university homework problem set, I have some
> reservations.
>
>
> This topic is very much in the zeitgeist, by the way:
>
> https://thenextweb.com/dd/2017/05/30/lets-teach-
> computer-science-students-to-cheat/#.tnw_YelJZVuo
>
> https://www.nytimes.com/2017/05/29/us/computer-science-
> cheating.html?_r=2
>
>
> > Thank you all for your views. I was hesitating for the same reason. Now
> I'm
> > clear that I shouldn't go for a blog that gives straightforward solution
> > for the challenges.
>
> Meena, I do want to add: if you do something like this, focus on the
> process rather than the end-solution, because that's the part that's
> worthwhile.
>
>
> Good luck!
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Coming from R, what's a good IDE editor? I've tried PyCharm and Spyder

2017-06-02 Thread Ben Finney
C W  writes:

> I am an R user learning Python. What is a good editor?

Either of Vim or Emacs – together with a good multi-tabbed terminal
program – make an excellent programmer IDE.

-- 
 \“When I was a baby I kept a diary. Recently I was re-reading |
  `\   it, it said ‘Day 1: Still tired from the move. Day 2: Everybody |
_o__)  talks to me like I'm an idiot.’” —Steven Wright |
Ben Finney

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor