Python slow to start on Windows - python

I noticed my Python code always takes longer to run on Windows than it does on Mac. Is there some way to improve this? The Windows machine is very powerful so I don't think it's a hardware issue (36 core Xeon, 96GB RAM, SSD). Python versions are similar, I'm running 3.7.9 on Windows 10, and 3.7.7 on MacOS Mojave.
For example, a simple print statement takes 7 times longer. Checking the version takes 12 times longer.
I uninstalled all pip modules on Windows.
I'm trying to write some very lightweight scripts where fast runtime is important.
$ time python3 -c "print('hello world')"
hello world
real 0m0.030s
user 0m0.019s
sys 0m0.009s
$ time python3 --version
Python 3.7.7
real 0m0.015s
user 0m0.003s
sys 0m0.005s
And on Windows 10 Powershell:
(Measure-Command {python -c "print('hello world')"}).TotalSeconds
0.2249363
(Measure-Command {python --version}).TotalSeconds
0.1776381
Edit: I captured the events with SysInternals Process Monitor and it shows 11,222 events for a single invocation of python --version. Wow, no wonder it takes so long! Unfortunately this doesn't really explain it, because it shows 0.233 seconds delay between "Thread Create" and Load Image".

Related

asyncio DatagramProtocol does not print to console but does so in sublime text window [duplicate]

I'm using mingw with msys and mintty on windows. I have a problem that msys and mintty are somehow not flushing output until a command is finished. This means I can't really run any interactive programs.
For example, if I have in C:
printf("Test\n");
the output won't appear until the program has terminated. However, if I have:
printf("Test\n"); fflush(stdout);
then the output appears immediately. If I use msys without mintty or the windows console, then everything works normally.
So my question, what's going on with msys and mintty?
This can be an issue when msys uses the rxvt shell under a number of scenarios. In cases where I see this problem, I ask msys to use the native Windows shell for its console. For example:
C:\MinGW\msys\1.0\msys.bat --no-rxvt
I thought that modern MSYS installations default to using the native shell as MSYS developers seem to prefer it. I have other issues with the native shell that drive me to use the rxvt shell, so I do infrequently run into this issue.
C:\MinGW\msys\1.0\msys.bat --rxvt
I find that the rxvt shell usually works fine except for certain applications that are built as "console" utilities meant to run from a command-line.
The only thing that worked for me was to precede the command with winpty ...
$ winpty java ClassName
It causes unbuffered output to be 3x slower and buffered output to be 5x slower (in my case, with Java).
To always have a command invisibly invoked by winpty ...
$ cd ~
$ pwd -W
... add the following line to .bashrc ...
alias java="winpty java"
... then restart terminal and ignore the (one-time) warning message.

Is anacron deprecated for Mac? How come I see no output when I run anacron?

I'm running Mac OSX 10.10, Yosemite, and am trying to set up an anacron job that runs a python script weekly.
My anacron tab is as follows:
# /etc/anacrontab
#period delay job-identifier command
7 10 cron.test /absolute/path/to/my/doc/test.py
Nothing happens when I run sudo anacron -fn, and no timestamp file is created when I run anacron -u. The python script is executable, and I've included #!/usr/bin/env python at the top. How can I fix this and get anacron to run?
P.S. - As an aside, I would prefer not to use launchd. What kind of program accepts its inputs in a pseudo-XML format in 2017??
It seems that anacron is no longer available for macOS, or never was at all according to this comment: https://apple.stackexchange.com/a/227308/176514
I'm afraid you may need to take a look at launchd. More about that here:
How do I set a task to run every so often?
EDIT:
After some searching, it seems that this link has the latest version, made for 10.4 Tiger. I'm not sure that will work with Yosemite, but it is worth a shot.
https://web.archive.org/web/20100723043612/http://members.cox.net/18james/anacron-tiger.html

Loading NCBITaxa crashes

I've been using the ete2 module on very powerful servers for some time.
Everything was fine until it started going very slowly (one get_taxid_translator() function per minute), now I cannot even get past ncbi = NCBITaxa() assignment.
I have uninstalled and reinstalled anaconda2, tried updating to ete3, everything works fine on our 'development servers' but still cannot get past the ncbi = NCBITaxa() line in any piece of software on our normal servers. Even the following script fails to finish
#!/usr/bin/env python
from ete3 import NCBITaxa
ncbi = NCBITaxa()
print "Finished"
Has this happened to anyone else? Do I need to downgrade any dependencies? Could it be a permissions issue?
When I run the basic script ctrl+c nor ctrl+z will escape the script and I have to use kill -9 <job-id> to kill the script. If I wait too long the process enters an uninterruptible sleep.
Thank you in advance,
Alexis.
Python 2.7.12 :: Anaconda custom (64-bit)
gcc (GCC) 5.4.0

Using Anaconda Python, esp. ipython, in cygwin, esp. emacs

I am working on a good Python environment for use on a Windows 7 machine. I am a big emacs fan, and like using the windows native build that's part of cygwin (emacs-w32). This way, I have access to all the cygwin tools from within emacs.
I also really like Anaconda's python distribution. I really don't feature downloading and maintaining all those packages myself, esp. within cygwin.
Also a big ipython fan.
On a Linux cluster, I'm having good luck using ipython as my python interpeter within emacs. I make a lot of plots, so matplotlib has to work too.
So I'm trying to get "ipython interpeter within cygwin emacs" to work.
Is this a good idea? Better ways to go? I know there's Spyder, but I honestly like working within emacs for editing .py files. Not just emacs keybindings - the whole emacs environment (grep, ediff, dired, etc etc).
Right now, I've gotten emacs to pick up ipython in the python 3 anaconda install. It runs, but I get extransous characters, e.g.:
^A^BIn [^A^B1^A^B]: ^A^B
instead of In [ 1 ]:
Also figure windows tend to not work (figure appears, but Windows says Not Responding, plots don't appear).
Thanks.
Update:
Thanks for the response. I did some more playing. To be exact:
* Setup bash path so Anaconda python and ipython found
* Started ConEmu (windows terminal program)
* ran bash from a cmd (dos) prompt
* ran cygwin's emacs: emacs -nw -Q (no window and no customization)
* Open .py file, C-c C-z, runs Anaconda python -i
* Get these messages:
Make dedicated process? (y or n) n
Making python-shell-interpreter local to Python while let-bound!
Making python-shell-interpreter-args local to Python while let-bound!
funcall: Args out of range: "^M", 0, 2
The final line appears in the emacs "status line" at the bottom. There is a buffer with Python running, seems to be fine. Except Ctrl-D doesn't work. If I type 'quit', I get the message "Use quit() or Ctrl-Z plus Return to exit." What happened to Ctrl-D?
If I repeat the exercise with ipython, the same messages are given, ipython buffer runs, I get the random ^A^B's, Ctrl-D doesn't work.

FreeBSD - Running Python code in different processors

I want to run two python scripts.
Each one takes long time to complete.
I am working on a dual core FreeBSD machine and want to make sure that I use both the cores.
When I run both the scripts I find that both end up running in the same CPU.
How can I control that two scripts are taken by different CPUs?
I know in Linux we can specify taskset -c X python foo.py where X is the CPU number liks 0,1,2.
How can I do something similar in FreeBSD system.
The term you are looking for is "CPU affinity."
cpuset -c -l X python foo.py
See How to set CPU affinity for a process in FreeBSD for more details.

Categories