[issue40093] ThreadPoolExecutor with wait=True shuts down too early

2020-03-29 Thread gaoxinge


gaoxinge  added the comment:

> I assume what you mean is that while shutdown will wait, it won't accept any 
> new job/future after it is called.

Yes, you are right. This is a feature of the ThreadPoolExecutor.

--

___
Python tracker 
<https://bugs.python.org/issue40093>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40093] ThreadPoolExecutor with wait=True shuts down too early

2020-03-29 Thread gaoxinge


gaoxinge  added the comment:

The workflow is like below:

- executor submit wait_on_future, and return the future f
- executor call shutdown
- executor submit pow (because executor already call shutdown, this submit will 
fail and raise a runtime error)
- then fail above will cause work thread fail when running wait_on_future
- then work thread will set both done singal and exception to f, which is the 
future of wait_on_future

--

___
Python tracker 
<https://bugs.python.org/issue40093>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40093] ThreadPoolExecutor with wait=True shuts down too early

2020-03-29 Thread gaoxinge


gaoxinge  added the comment:

```
from concurrent.futures import ThreadPoolExecutor
from time import sleep

def wait_on_future():
sleep(1)
print(f.done()) # f is not done obviously
f2 = executor.submit(pow, 5, 2)
print(f2.result())
sleep(1)


executor = ThreadPoolExecutor(max_workers=100)
f = executor.submit(wait_on_future)
executor.shutdown(wait=True)
print(f.done()) # True
print(f.result())   # raise errror: cannot schedule new futures after 
shutdown
# print(f.exception())
```

Actually `executor.shutdown(wait=True)` works, it really wait f to be done.

--
nosy: +gaoxinge

___
Python tracker 
<https://bugs.python.org/issue40093>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40099] modify code format of json library for pep7,8

2020-03-28 Thread gaoxinge


Change by gaoxinge :


--
components: Library (Lib)
nosy: gaoxinge
priority: normal
pull_requests: 18575
severity: normal
status: open
title: modify code format of json library for pep7,8
type: enhancement
versions: Python 3.9

___
Python tracker 
<https://bugs.python.org/issue40099>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38382] statistics.harmonic_mean fails to raise error with negative input that follows a 0

2019-10-29 Thread gaoxinge


gaoxinge  added the comment:

Your point makes sense. We should still also consider the `int`, `Decimal`, 
`Fraction`, `math.nan`, `math.inf`, `np.int` and so on. So

- `geometric mean`: input should be positive (>= 0)
- `harmonic mean`: input should be nonzero (!= 0)
- `mean` or `fmean`: no input restriction

--

___
Python tracker 
<https://bugs.python.org/issue38382>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38382] statistics.harmonic_mean fails to raise error with negative input that follows a 0

2019-10-29 Thread gaoxinge


gaoxinge  added the comment:

The document 
https://github.com/WarrenWeckesser/cpython/blob/master/Lib/statistics.py#L389 
in `harmonic_mean` is out-dated. I think we can simply follow the wiki:

- [arithemic mean](https://en.wikipedia.org/wiki/Arithmetic_mean)
- [geometric mean](https://en.wikipedia.org/wiki/Geometric_mean)
- [harmonic mean](https://en.wikipedia.org/wiki/Harmonic_mean)

--

___
Python tracker 
<https://bugs.python.org/issue38382>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue38382] statistics.harmonic_mean fails to raise error with negative input that follows a 0

2019-10-29 Thread gaoxinge


gaoxinge  added the comment:

I think that three kinds of mean should behave like:

- `geometric mean`: input should be float, finite and positive
- `harmonic mean`: input should be float, finite and nonzero
- `mean` or `fmean`: input should be float, finite

Otherwise these mean functions should raise a `StatisticsError`. 

Two points that we should pay attention to:

- Why every input should be float? Because it is a statstics library, we should 
focus on the float instead of complex number or string or `math.nan`.

- Why every input shoud be finite? Becuse we should get rid of `math.inf`.

--
nosy: +gaoxinge

___
Python tracker 
<https://bugs.python.org/issue38382>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34268] run pool.submit in callback when future.set_result

2018-07-28 Thread gaoxinge


New submission from gaoxinge :

## abstract

When using concurrent.futures.ThreadPoolExecutor module, if we code pool.submit 
in callback, the callback may be not run. This is because main thread will 
terminate, and call _python_exit to add none to _work_queue before subthread 
run callback.

## code

```
# -*- coding: utf-8 -*-
from concurrent.futures import ThreadPoolExecutor


def func(x, y):
import time
time.sleep(1)
return x + y


def do_many(n):

def callback(fut):
nonlocal n
result = fut.result()
print('Got: ', result)
n -= 1
if n > 0:
future = pool.submit(func, n, n)
future.add_done_callback(callback)

if n > 0:
future = pool.submit(func, n, n)
future.add_done_callback(callback)
 # _python_exit will be called here, and then 
 # add none to _work_queue

pool = ThreadPoolExecutor(max_workers=8)
do_many(10)
```

## result and expectation

The code's result may be 

```
Got:  20
Got:  18
Got:  16
Got:  14
Got:  12
Got:  10
Got:  8
Got:  6
```

But my expectation is

```
Got:  20
Got:  18
Got:  16
Got:  14
Got:  12
Got:  10
Got:  8
Got:  6
Got:  4
Got:  2
```

## question

Is my expectation reasonable?

### if not reasonable

If not, my solution is 

```
from concurrent.futures import ThreadPoolExecutor


def func(x, y):
import time
time.sleep(1)
return x + y


def do_many():

def callback(fut):
global n
result = fut.result()
print('Got: ', result)
n -= 1
if n > 0:
future = pool.submit(func, n, n)
future.add_done_callback(callback)

if n > 0:
future = pool.submit(func, n, n)
future.add_done_callback(callback)

n = 10
pool = ThreadPoolExecutor(max_workers=8)
do_many()
while n > 0:  # use while to block main thread
pass
```

and is there any elegant solution?

### if reasonable

...

--
components: Library (Lib)
messages: 322605
nosy: gaoxinge
priority: normal
severity: normal
status: open
title: run pool.submit in callback when future.set_result
type: behavior
versions: Python 3.6

___
Python tracker 
<https://bugs.python.org/issue34268>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com