Skip to content

Instantly share code, notes, and snippets.

@baojie
Last active December 20, 2015 17:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baojie/6172644 to your computer and use it in GitHub Desktop.
Save baojie/6172644 to your computer and use it in GitHub Desktop.
Call python 3 from python 2 virtualenv
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))
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)
sudo pip3 install simple-date
virtualenv env
source env/bin/activate
pip install execnet
python 2call3.py
$ 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