Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
pygolang
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
pygolang
Commits
307b9ce2
Commit
307b9ce2
authored
Mar 06, 2025
by
Boxiang Sun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gpython: Support unbuffered mode option -u
parent
6aec4784
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
1 deletion
+41
-1
gpython/__init__.py
gpython/__init__.py
+2
-1
gpython/gpython_test.py
gpython/gpython_test.py
+39
-0
No files found.
gpython/__init__.py
View file @
307b9ce2
...
...
@@ -41,7 +41,7 @@ $GPYTHON_RUNTIME=threads.
from
__future__
import
print_function
,
absolute_import
_pyopt
=
"c:Eim:OvVW:X:"
_pyopt
=
"c:Eim:O
u
vVW:X:"
_pyopt_long
=
(
'version'
,)
# pymain mimics `python ...`
...
...
@@ -117,6 +117,7 @@ def pymain(argv, init=None):
'-O'
,
# optimize
'-v'
,
# trace import statements
'-X'
,
# set implementation-specific option
'-u'
,
# unbuffered mode
):
# but keep `-X gpython.*` in user part of argv in case of reexec
...
...
gpython/gpython_test.py
View file @
307b9ce2
...
...
@@ -245,6 +245,45 @@ def test_pymain():
_
,
)
# Check -u behaviours
if
PY2
:
cmd
=
[
'python2'
]
code
=
(
'import time; '
'print(time.time()); '
'time.sleep(2); '
'print(time.time())'
)
cmd
.
extend
([
'-c'
,
code
])
unbuffer_cmd
=
cmd
[:]
unbuffer_cmd
.
insert
(
1
,
'-u'
)
p
=
subprocess
.
Popen
(
cmd
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
_
=
p
.
stdout
.
readline
().
strip
()
t0
=
time
.
time
()
_
=
p
.
stdout
.
readline
().
strip
()
t1
=
time
.
time
()
delay_buffer
=
t1
-
t0
u_p
=
subprocess
.
Popen
(
unbuffer_cmd
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
_
=
u_p
.
stdout
.
readline
().
strip
()
t3
=
time
.
time
()
_
=
u_p
.
stdout
.
readline
().
strip
()
t4
=
time
.
time
()
delay_unbuffer
=
t1
-
t0
p
.
wait
()
u_p
.
wait
()
# Only under unbuffered mode, we can sense the time.sleep(2)
# so compare the time difference between unbuffered and buffered
assert
delay_unbuffer
>
delay_buffer
else
:
_
=
pyout
([
'-u'
,
'-c'
,
'import sys; print(sys.stdout.buffer)'
],
cwd
=
testdata
)
assert
_
==
b"<_io.FileIO name='<stdout>' mode='wb' closefd=False>
\
n
"
_
=
pyout
([
'-c'
,
'import sys; print(sys.stdout.buffer)'
],
cwd
=
testdata
)
assert
_
==
b"<_io.BufferedWriter name='<stdout>'>
\
n
"
def
test_pymain_print_function_future
():
if
PY2
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment