-
-
Save baojie/6172644 to your computer and use it in GitHub Desktop.
Call python 3 from python 2 virtualenv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from simpledate import * | |
for date in '1/6/2013 BST', '1/6/2013 EST', 'Tue, 18 Jun 2013 12:19:0$ | |
print(best_guess_utc(date)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import execnet | |
gw = execnet.makegateway("popen//python=/usr/bin/python3") | |
channel = gw.remote_exec(""" | |
from simpledate import * | |
while 1: | |
x = channel.receive() | |
if x is None: | |
break | |
channel.send(best_guess_utc(x).isoformat()) | |
""") | |
for x in '1/6/2013 BST', '1/6/2013 EST', 'Tue, 18 Jun 2013 12:19:09 -0400': | |
channel.send(x) | |
print channel.receive() | |
channel.send(None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo pip3 install simple-date | |
virtualenv env | |
source env/bin/activate | |
pip install execnet | |
python 2call3.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat 2call3.py | pypy -m timeit -n 10000 | |
10000 loops, best of 3: 0.0016 usec per loop | |
$ cat 2.py | pypy -m timeit -n 10000 | |
10000 loops, best of 3: 0.00241 usec per loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment