Re: PEP 594 cgi & cgitb removal

2019-05-29 Thread Robin Becker

...


More specifically, with CGI the webserver starts a new process for every single request. That's bad enough for a light C program, 
but it's certainly not a good idea to start a whole new Python process for every request. At least not for any production website 
or web service that serves any real amount of traffic.


That is, for those who didn't know, the reason why CGI fell out of use quite 
some time ago.



Well I'm afraid I cannot agree with that reasoning. ReportLab used cgi exactly because it starts a new process; most of the 
reports that are generated take more than a second to generate so the startup time is of less importance. Starting up in a clean 
state is of importance because the sharing of resources across different reports often leads to buggy report code such as relying 
on an earlier report to load fonts, define colours etc etc. This could perhaps have been done with multiple interpreters eg 
mod_python, but I think the isolation there is not perfect especially with C extensions.


It might be that the new 'cgi' doesn't use the older api and in that sense we could just use wsgi or whatever the new interface 
is, but I would still use cgitb to provide nicely formatted traceback html.

--
Robin Becker

--
https://mail.python.org/mailman/listinfo/python-list


Re: How to use ssh-agent in windows in python?

2019-05-29 Thread Fc Zwtyds

在 2019-05-27 11:19, Cameron Simpson 写道:

The output of "ssh-agent -s" is Bourne shell variable assignment syntax. 
You need to parse that and then install those values in so.environ 
before calling the second command. The subprocess module has methods for 
collecting the output of a command (see the communicate method).


Hi,
  I want to rewrite the shell script to python script so I have had 
changed the "ssh-agent -s" to 'ssh-agent cmd' in python script for the 
consistence on windows.
  There are two inputs in the two commands. I tried code use 
communicate method and write method and got errors:

Cannot send input after starting communication
and
ValueError: write to closed file
  I found the communicate method just run one times.

The manual input process is as follows:
1. run cmd.exe
2. input 'ssh-agent cmd' press return, the window display a new prompt.
3. input 'ssh-add id_rsa' and press return, it will ask the id_rsa 
password. After input correctly password, it will display 'Identity 
added: id_rsa (id_rsa)' and a new prompt.


import subprocess

p = subprocess.Popen('cmd', stdin = subprocess.PIPE, stdout = 
subprocess.PIPE, stderr = subprocess.PIPE, shell = True, 
universal_newlines = True)

outinfo, errinfo = p.communicate('ssh-agent cmd\n')
#p.stdin.write('ssh-add id_rsa\n')
#p.stdin.flush()
print('outinfo is \n %s' % stdoutinfo)
print('errinfo is \n %s' % stderrinfo)

  After a lot of searching and learning I still do not know how to code 
it, I realy need help.


Thanks a lot.
--
https://mail.python.org/mailman/listinfo/python-list


Re: problem in installing packages

2019-05-29 Thread Joe Pfeiffer
Joel Goldstick  writes:

> On Wed, May 29, 2019 at 1:17 AM Sri Tharun  wrote:
>>
>> Problem not resolved.Yet
>>
>> On Wed 29 May, 2019, 6:39 AM Tharun,  wrote:
>>
>> >
>> > >>> sudo apt-get update
>> >
>> >   File "", line 1
>> >
>> > sudo apt-get update
>> >^
>> > SyntaxError: invalid syntax
>> >
>> > This was the problem
>> >
>> > Sent from Mail  for
>> > Windows 10
>
> It appears you are trying to execute a linux shell command while in
> the python repl.  exit python, and try again

And, if he is posting from the same computer as he is seeing the problem
on, it's a Windows box so neither "sudo" nor "apt-get" is going to
work anyway.
-- 
https://mail.python.org/mailman/listinfo/python-list


Threading Keyboard Interrupt issue

2019-05-29 Thread nihar Modi
I have written a simple code that involves threading, but it does not go to
except clause after Keyboard interrupt. Can you suggest a way out. I have
pasted the code below. It does not print 'hi' after keyboard interrupt and
just stops.

import threading

def loop():
 while true:
  print('hello')
  time.sleep(5)

if __name__ == '__main__':
 try:
  y = threading.Thread(target = loop, args = ())
  y.start()
 except KeyboardInterrupt:
  print('hi')

The program does not print hi and terminates immediately after ctrl+c
-- 
https://mail.python.org/mailman/listinfo/python-list


Re:

2019-05-29 Thread Bo YU
On Wed, May 29, 2019 at 1:19 PM Sri Tharun  wrote:

> Why I am unable to install packages
>
If you really want to get help from the list,please give us more info.

> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Threading Keyboard Interrupt issue

2019-05-29 Thread Chris Angelico
On Thu, May 30, 2019 at 1:45 AM nihar Modi  wrote:
>
> I have written a simple code that involves threading, but it does not go to
> except clause after Keyboard interrupt. Can you suggest a way out. I have
> pasted the code below. It does not print 'hi' after keyboard interrupt and
> just stops.

Threads allow multiple things to run at once. The entire *point* of
spinning off a new thread is that the main code keeps going even while
the thread runs. They are independent.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Trouble Downloading Python and Numpy

2019-05-29 Thread Contreras, Brian J
Good Morning,

I am a research student at the Georgia Institute of Technology. I have made 
multiple attempts to download different versions of Python with Numpy on my 
Microsoft Surface Book with no success.

I ensured that I have space for the program and the latest windows 10 update, I 
still am unable to open any python files or write code within the program. I 
was told by a colleague that I may need a python path environmental variable, 
but I have not found asite that provides this.

If I could get some support with the download I would greatly appreciate it.

Warm Regards,

Brian Contreras
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Trouble Downloading Python and Numpy

2019-05-29 Thread Shakti Kumar
On Wed, 29 May 2019 at 9:29 PM Contreras, Brian J 
wrote:

> Good Morning,
>
> I am a research student at the Georgia Institute of Technology. I have
> made multiple attempts to download different versions of Python with Numpy
> on my Microsoft Surface Book with no success.
>

Since you need numpy and as a grad student too, I'll strongly suggest you
to look for "installing anaconda on Windows". It's GUI based installation
would be a good start especially for people who are struggling with python
installations on windows.


> (Clipped for brevity)
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
Sent from Shakti’s iPhone
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Trouble Downloading Python and Numpy

2019-05-29 Thread Shakti Kumar
On Wed, 29 May 2019 at 9:38 PM Shakti Kumar 
wrote:

>
>
> On Wed, 29 May 2019 at 9:29 PM Contreras, Brian J 
> wrote:
>
>> Good Morning,
>>
>> I am a research student at the Georgia Institute of Technology. I have
>> made multiple attempts to download different versions of Python with Numpy
>> on my Microsoft Surface Book with no success.
>>
>
> Since you need numpy and as a grad student too, I'll strongly suggest you
> to look for "installing anaconda on Windows". It's GUI based installation
> would be a good start especially for people who are struggling with python
> installations on windows.
>

Forgot to mention this,
Anaconda comes prepackaged with numpy, pandas, scripy and other data
analysis libs. So you won't need to pip/conda install them separately


>
>> (Clipped for brevity)
>
>
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
> --
> Sent from Shakti’s iPhone
>
-- 
Sent from Shakti’s iPhone
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Threading Keyboard Interrupt issue

2019-05-29 Thread David Raymond
That's a little weird, and my running it works slightly differently. Please 
paste exactly what you're running (no time import and true being lowercase for 
example means we couldn't copy and paste it and have it immediately run)

In your script, the main thread hits y.start() which completes successfully as 
soon as the new thread gets going, so it exits the try/except block as a 
success. Then since there's no more code, the main thread completes.

The loop thread you started inherits the daemon-ness of the thread that called 
it, so by default it's started as a regular thread, and not a daemon thread. As 
a regular thread it will keep going even when the main thread completes.

Keyboard interrupts are only received by the main thread, which in this case 
completes real quick.

So what happens for me is that the main thread runs to completion instantly and 
leaves nothing alive to receive the keyboard interrupt, which means the loop 
thread will run forever until killed externally. (Task manager, ctrl-break, etc)

In this case, even if the main thread _was_ still alive to catch the keyboard 
interrupt, that exception does not get automatically passed to all threads, 
only the main one. So the main thread would have to catch the exception, then 
use one of the available signaling mechanisms to let the other threads know, 
and each of those other threads would have to consciously check for your signal 
of choice to see if the main thread wanted them to shut down.

Or, the other threads would have to be declared as demonic before they were 
started, in which case they would be killed automatically once all non-daemonic 
threads had ended.


-Original Message-
From: Python-list 
[mailto:python-list-bounces+david.raymond=tomtom@python.org] On Behalf Of 
nihar Modi
Sent: Wednesday, May 29, 2019 4:39 AM
To: python-list@python.org
Subject: Threading Keyboard Interrupt issue

I have written a simple code that involves threading, but it does not go to
except clause after Keyboard interrupt. Can you suggest a way out. I have
pasted the code below. It does not print 'hi' after keyboard interrupt and
just stops.

import threading

def loop():
 while true:
  print('hello')
  time.sleep(5)

if __name__ == '__main__':
 try:
  y = threading.Thread(target = loop, args = ())
  y.start()
 except KeyboardInterrupt:
  print('hi')

The program does not print hi and terminates immediately after ctrl+c
-- 
https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Threading Keyboard Interrupt issue

2019-05-29 Thread eryk sun
On 5/29/19, David Raymond  wrote:
>
> Keyboard interrupts are only received by the main thread, which in this case
> completes real quick.
>
> So what happens for me is that the main thread runs to completion instantly
> and leaves nothing alive to receive the keyboard interrupt, which means the
> loop thread will run forever until killed externally. (Task manager,
> ctrl-break, etc)

The main thread is still running in order to join non-daemon threads.
In Windows, the internal wait used to join a thread can't be
interrupted by Ctrl+C, unlike POSIX platforms.
The Windows build could be modified to support Ctrl+C in this case,
but I'm only certain about the current build that uses emulated
condition variables.

When I run the OP's script in Linux, acquiring the internal
thread-state lock (which normally waits until the lock is reset when
the thread exits) gets interrupted by the SIGINT signal, and
KeyboardInterrupt is raised:

Exception ignored in: 
Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 1294, in _shutdown
t.join()
  File "/usr/lib/python3.6/threading.py", line 1056, in join
self._wait_for_tstate_lock()
  File "/usr/lib/python3.6/threading.py", line 1072, in
_wait_for_tstate_lock
elif lock.acquire(block, timeout):
KeyboardInterrupt
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to use ssh-agent in windows in python?

2019-05-29 Thread Cameron Simpson

On 29May2019 22:37, Fc Zwtyds  wrote:

在 2019-05-27 11:19, Cameron Simpson 写道:
The output of "ssh-agent -s" is Bourne shell variable assignment 
syntax. You need to parse that [...]


 I want to rewrite the shell script to python script so I have had 
changed the "ssh-agent -s" to 'ssh-agent cmd' in python script for the 
consistence on windows.


I'm not sure you need to do that. In fact, I'm fairly sure you don't.

When you run "ssh-agent cmd" the agent starts as before, but instead of 
reporting its communication socket and process id it dispatches command 
and runs for the duration of that command, then exits.


Before ssh-agent dispatches "cmd" (here I mean a generic command, though 
that command might well be "cmd.exe"), it first puts the necessary 
environment variables into the command's environment.


There are two such values: the communication socket and the ssh-agent 
process id. The socket is so that the other ssh commands can talk to it, 
and the process id is so that it can be terminated when no longer 
wanted. For the "ssh-agent cmd" form there's no need to use the process 
id, since ssh-agent itself will exit after "cmd" finishes.


Let's look at what "ssh-agent -s" produces. This is on a UNIX system (my 
Mac):


 [~]fleet*> ssh-agent -s
 SSH_AUTH_SOCK=/Users/cameron/tmp/ssh-vuvXU6vrCAxz/agent.50746; export 
SSH_AUTH_SOCK;
 SSH_AGENT_PID=50754; export SSH_AGENT_PID;
 echo Agent pid 50754;

You can see the socket path and the process id there. The paths will be 
a bit different on Windows.


So if I do a process listing (this is a UNIX "ps" command, you will need 
to do the equivalent Windows thing) and search for that process id we 
see:


 [~]fleet*1> ps ax | grep 62928
 62928   ??  Ss 0:00.00 ssh-agent -s
 66204 s027  S+ 0:00.00 grep 62928

So there's the ssh-agent process and also the "grep" command itself 
because the process id is present on its command line.


Note that at this point my shell (cmd.exe equivalent in Windows) does 
not know about the new ssh-agent. This is because I haven't put those 
environment values into the shell environment: the output above is just 
written to the display. So when I go:


 [~]fleet*> ssh-add -l

it shows me 4 ssh keys. This is because I already have an agent which 
has some keys loaded. If my shell were talking to the new agent the list 
would be empty. Let's do that.


 [~]fleet*> SSH_AUTH_SOCK=/Users/cameron/tmp/ssh-vuvXU6vrCAxz/agent.50746
 [~]fleet*> SSH_AGENT_PID=50754
 [~]fleet*> export SSH_AUTH_SOCK SSH_AGENT_PID
 [~]fleet*> ssh-add -l
 The agent has no identities.

So now this shell is using the new agent. You see there's no magic here: 
other commands do not know about the agent until we tell then about it 
using these environment variables.


What I was suggesting is that you perform this process from Python, 
which I believe was your original plan.


So let's adapt the the comand you presented below, and also dig into why 
what you've tried hasn't worked. So, your subprocess call:


 import subprocess
 p = subprocess.Popen('cmd', stdin = subprocess.PIPE, stdout = subprocess.PIPE, 
stderr = subprocess.PIPE, shell = True, universal_newlines = True)
 outinfo, errinfo = p.communicate('ssh-agent cmd\n')
 print('outinfo is \n %s' % stdoutinfo)
 print('errinfo is \n %s' % stderrinfo)

This does the follow things:

1: Start a subprocess running "cmd". You get back a Popen object "p" for 
use with that process.


2: Run p.communicate("ssh-agent cmd\n"). This sends that to the input of 
the "cmd" subprocess and collects the output.


An important thing to know here is the .communicate is a complete 
interaction with the subprocess. The subprocess' _entire_ input is the 
string you've supplied, and the entire output of the subprocess until it 
completes is collected.


So, what's going on is this:

1: start "cmd"
2: send "ssh-agent cmd\n" to it.
3: collect output and wait for it to exit.

From "cmd"'s point of view:

1: Receive "ssh-agent cmd\n", causing it to run the "ssh-=agent cmd" 
command and then wait for it to exit.


2: ssh-agent starts and then runs another "cmd" and waits for _that_ to 
exit.


3: The second "cmd" processes its input, then exits. Note that becuase 
the input to the entire subprocess was "ssh-agent cmd\n", and the first 
"cmd" consumed that, there is no no more input data. So the second cmd 
exits immediately because there is no input.


4: The ssh-agent exist because the second "cmd" exited.

5: The first "cmd" sees the "ssh-agent cmd" command exit and looks for
another command to run from its input.

6: As before, there are no more input data. So the first "cmd" also 
exits.


And at that point .communicate sees the end of the output and returns 
it.


Because the subprocess is complete, your commented out "p.write" call 
fails. You can't do things that way with .communicate.


There are complicated (and error prone) ways to do more incremental 
input, not using .communicate. Let us not go there for now.


In

Re: How to use ssh-agent in windows in python?

2019-05-29 Thread Fc Zwtyds

在 2019-05-30 6:41, Cameron Simpson 写道:

On 29May2019 22:37, Fc Zwtyds  wrote:

在 2019-05-27 11:19, Cameron Simpson 写道:
The output of "ssh-agent -s" is Bourne shell variable assignment 
syntax. You need to parse that [...]


 I want to rewrite the shell script to python script so I have had 
changed the "ssh-agent -s" to 'ssh-agent cmd' in python script for the 
consistence on windows.


I'm not sure you need to do that. In fact, I'm fairly sure you don't.


...
...
...
The you could just use os.system() to run the other commands, because 
the environment now has the necessary environment settings.


See how you go.

Cheers,
Cameron Simpson  (formerly c...@zip.com.au)


Thank you very very much and your time.
I need a time to learn what you write to me.
Thank you again.

--
https://mail.python.org/mailman/listinfo/python-list


Re: Threading Keyboard Interrupt issue

2019-05-29 Thread eryk sun
On 5/29/19, Dennis Lee Bieber  wrote:
>
>   In the OP's example code, with just one thread started, the easiest
> solution is to use
>
>   y.start()
>   y.join()
>
> to block the main thread. That will, at least, let the try/except catch the
> interrupt. It does not, however, kill the sub-thread.

join() can't be interrupted by Ctrl+C in Windows. To work around this,
we can join a thread with a short timeout in a loop. If we're managing
queued work items with a thread pool, note that Queue.join doesn't
support a timeout. In this case we need to poll empty() in a loop with
a short time.sleep(). Or we can let the main thread block and use
ctypes to install a console control handler that sets a flag that
tells child threads to exit. Windows calls the control handler in a
new thread.
-- 
https://mail.python.org/mailman/listinfo/python-list


write function call _io_BufferedWriter_write_impl twice?

2019-05-29 Thread Windson Yang
My script looks like this:

f = open('myfile', 'a+b')
f.write(b'abcde')

And I also add a `printf` statement in the _io_BufferedWriter_write_impl

function.

static PyObject * _io_BufferedWriter_write_impl(buffered *self,
Py_buffer *buffer)
/*[clinic end generated code: output=7f8d1365759bfc6b
input=dd87dd85fc7f8850]*/
{
printf("call write_impl\n");
PyObject *res = NULL;
Py_ssize_t written, avail, remaining;
Py_off_t offset;
   ...

After I compiled then run my script. I found _io_BufferedWriter_write_impl

had
been called twice which I expected only once. The second time it changed
self->pos to an unexpected value too.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to use ssh-agent in windows in python?

2019-05-29 Thread eryk sun
On 5/29/19, Cameron Simpson  wrote:
>
> So start with this:
>
>   p = subprocess.Popen('ssh-agent -s', stdin = subprocess.PIPE, stdout =
> subprocess.PIPE, stderr = subprocess.PIPE, shell = True, universal_newlines
> = True)

I'm wary of relying on the default encoding here. ssh-agent probably
writes ASCII or ANSI text to the pipe, and Python defaults to decoding
as ANSI ('mbcs'). However, Windows filesystem paths can use any
Unicode characters. (A filename is a string of up to 255 16-bit
wchar_t values, sans reserved characters, regardless of whether it's
valid UTF-16LE, but let's assume it's valid Unicode text for the sake
of everyone's sanity.) This is a problem when a user name can't be
encoded with the system ANSI codepage. In particular, it's a concern
for the user's %temp% directory (i.e.
"C:/Users//AppData/Local/Temp") in the SSH_AUTH_SOCK
environment variable.

That said, at least for the MSYS2 build of ssh-agent.exe that's
included with Git, the user's %temp% directory is mapped to "/tmp" in
its emulated POSIX namespace, so this should be okay. Make sure the
Cygwin build behaves the same. Otherwise check whether there's a way
to force it to use UTF-8. MSYS2 apparently respects the LC_CTYPE
environment variable. Without LC_CTYPE set, it fails to even parse the
command line properly:

>>> bash = r'C:\Program Files\Git\usr\bin\bash.exe'
>>> command = 'echo αβγδε'
>>> subprocess.call([bash, '-c', command])
/usr/bin/bash: echo αβγδε: command not found
127

With it set, it parses the command correctly and writes UTF-8 encoded
text to stdout when it's a pipe or disk file:

>>> environ = os.environ.copy()
>>> environ['LC_CTYPE'] = 'en_US.utf8'
>>> subprocess.check_output([bash, '-c', command],
... env=environ, encoding='utf-8')
'αβγδε\n'
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: compiling 3.7.0 from source with custom libffi path

2019-05-29 Thread abhinav1205
Exactly same issue.. ctypes wont build .. pkg-config finds libffi, headers are 
located in configure and still 
INFO: Could not locate ffi libs and/or headers

python is getting really annoying to install .. not everyone has root 
privileges to install system-wide dependencies. 


On Tuesday, September 25, 2018 at 12:11:51 AM UTC+5:30, Fetchinson . wrote:
> On 9/24/18, Thomas Jollans  wrote:
> > On 2018-09-24 16:30, Fetchinson . via Python-list wrote:
> >> [fetch@fetch]$ grep LIBFFI_INCLUDE Makefile
> >> LIBFFI_INCLUDEDIR=  /opt/custom/lib/libffi-3.2.1/include
> >>
> >> So I'd say everything should work but it doesn't, I reran ./configure
> >> and also make of course.
> >
> > I'm confused. ./configure succeeds? Then where's the error?
> 
> Yes, ./configure succeeds, also make succeeds in general, so it
> produces a usable python executable but _ctypes is not compiled so
> _ctypes is not usable and can not be imported, libffi is only needed
> for _ctypes AFAIK. The error, or better said INFO message, comes from
> make:
> 
> INFO: Could not locate ffi libs and/or headers
> 
> Failed to build these modules:
> _ctypes
> 
> But nevertheless make install also succeeds, the only thing is that
> _ctypes does not work.
> 
> Cheers,
> Daniel
> 
> -- 
> Psss, psss, put it down! - http://www.cafepress.com/putitdown

-- 
https://mail.python.org/mailman/listinfo/python-list