question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cython.parallel.threadid unavailable in function arguments

See original GitHub issue

It looks like this is a valid cython code.

from cython import parallel
x = parallel.threadid()
print(x)

But this is not.

from cython import parallel
print(parallel.threadid())

This might be just a symptom of a larger issue. Many things are not possible with the cython module when compiled with cython, compared to when run with python. Like accessing its module object.

import cython
x = cython

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
da-woodscommented, May 9, 2020

print(parallel.threadid()) looks like a bug.


Not being able to assign the cython module isn’t. The Cython module isn’t really a proper module, should really only be cimported (a compile-time action), and doesn’t have an actual module object associated with it. It can be imported so it’s possible to write pure-Python code with optional Cython features.

If you were able to assign the cython module then people would do things like:

import cython

if something():
     x = cython
else:
     class Dummy:
         def cclass(self, var):
             return var
    x = Dummy()

@x.cclass
class C:
    pass

Suddenly you’ve made the choice of whether C is a cdef or regular class a runtime decision rather than a compile-time decision…

0reactions
da-woodscommented, May 14, 2020

Thanks for the output. I’m quite puzzled by it though. When I compare the .c file from tests/run/parallel.pyx (i.e. the two tests that are failing) with and without my PR the only differences are due to the extra test I added. If I revert the extra test I added then diff tells me that they’re identical.

So I don’t know I’m afraid… I guess the PR should be treated with caution because of what you say but I really don’t understand where the differences could be coming from.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Parallelism — Cython 3.0.0a11 documentation
Variables that are private in the parallel block are unavailable after the parallel block. Example with thread-local buffers. Pure Python Cython. from cython....
Read more >
Prange slowing down Cython loop - Stack Overflow
I was planning to set up a monte carlo framework with a pipeline structure: basic rand >> random variable >> function of random...
Read more >
Parallel computing in Cython - threads - Neal Hughes
How to run multiple threads in Cython. ... The perfect use case is applying a function element wise over a large array.
Read more >
Using Parallelism - Cython 0.19.1 Documentation
Variables that are private in the parallel block are unavailable after the parallel block. Example with thread-local buffers: from cython.parallel import ...
Read more >
Using Parallelism - 《Cython 3.0 Documentation》 - 书栈网
cython.parallel. prange ([start,] stop[, step][, nogil=False][, schedule=None[, chunksize=None]][, num_threads=None]) · This function can be used ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found