0

I am calling a C-library from python with ctypes. This library has some global variables defined inside. I call it within python with

 lib = CDLL(path/to/library)

I need to use this library in the same code, but with different value of the global variables in the two cases. If I create two instances of the library with the above line (lib1 and lib2), will the instance be independent? or will the global variables be the same in the two cases?

simona
  • 2,009
  • 6
  • 29
  • 41
  • 1
    Why don't you try it and find out? :-) – mgilson Jun 21 '16 at 16:34
  • well because ideally there would be a language standard. sometimes dirty trick work in some cases, but they are not robust and fail in some other case. I would like to know if it works of course, but also what the standard behaviour should be – simona Jun 21 '16 at 16:39
  • That's a fair comment, but if you're worried about portability, you should probably state what you need to support. Since you're using `CDLL`, you're probably already limited to windows. From there, Cpython probably just supports what windows supports so we can [broaden the search to other languages](http://stackoverflow.com/q/12530022/748858). – mgilson Jun 21 '16 at 16:46
  • ? I am using Linux – simona Jun 21 '16 at 16:58
  • Depends on how your OS handles share-libraries. I suspect that even if the code is shared, each instance will store its data separately. – martineau Jun 21 '16 at 17:24
  • @simona -- then I guess I learned something new today ... – mgilson Jun 21 '16 at 17:25

0 Answers0